1

Please help me in figuring this one out. So I am trying to display the number of records with the same value into a label in my form.

SELECT Status_ , COUNT(Status_) FROM ISSUANCE WHERE Status_ = 'Draft' GROUP BY Status_

How can I display it? Thank you.

    Dim disconn As New SqlConnection("Server = EURIZZE-PC;Database = INTERTRANS;Integrated Security = SSPI;")
    Dim DataSet2 As New DataSet


    Dim sqlcon As String = "SELECT ISSUANCE.Status_ , COUNT(Status_) FROM ISSUANCE WHERE Status_ = 'Draft' GROUP BY Status_"
    Dim sqlda As New SqlDataAdapter(sql, thisConnection)

    da.Fill(DataSet1, "ISSUANCE")
    NameLabel1.DataBindings.Add("text", DataSet1, "") 'So I am having trouble on how to display it. Because the rowcount is not a permanent column.
noob-programmer
  • 61
  • 1
  • 1
  • 8

3 Answers3

1

Probably change your query with a case expression like

SELECT Status_ , 
SUM(CASE WHEN Status_ = 'Draft' THEN 1 ELSE 0 END) AS NewSum
FROM ISSUANCE 
GROUP BY Status_;
Rahul
  • 76,197
  • 13
  • 71
  • 125
1

Are you working with win-forms? You didn't provide much information here...

Label newlabel = new Label();
newlabel.Text = ""; // <- put your query-result in here
S. Jerk
  • 29
  • 8
0

Try following method

  Dim disconn As New SqlConnection("Server = EURIZZE-PC;Database = INTERTRANS;Integrated Security = SSPI;")
            Dim retval As String
            Dim arRetval As String()
            Using cmd1 As New SqlCommand("", disconn)
                With cmd1
                    .CommandText = "SELECT Status_ +'|'+cast( COUNT(Status_)as varchar) FROM ISSUANCE WHERE Status_ = 'Draft' GROUP BY Status_"
                    retval = .ExecuteScalar
                End With
            End Using
            If retval <> String.Empty Then
                arRetval = retval.Split("|")
                count.Text = arRetval(0) & " " & arRetval(1)
            End If
Vivek S.
  • 19,945
  • 7
  • 68
  • 85