troubleshooting Question

Count number of rows retrieved from SQL query and entered into datagrid in VB.Net

CSSTRADER asked on
Visual Basic.NET
9 Comments1 Solution11252 ViewsLast Modified:
I am using VB.Net to query a SQL database and am placing the information retrieved in a datagrid. I need to know how to count the number of rows that meet the query criteria and placed in the datagrid itself for the user to see.  I have posted the code for my query below, but am not sure what I should do to count the number of hits.  Your help is greatly appreicated...thanks

 If boolaction = False And boolcsrep = False Then
            'enter sql date query
            ' dateactionrep = "Select * From ActionManagement where date between '" & begindate.ToShortDateString & " ' and '" & enddate.ToShortDateString & "'"
            Dim dtdate1 As String
            Dim dtdate2 As String
            Dim cmd As SqlCommand = SqlConnection1.CreateCommand
            Dim rowcount As Integer

            dtdate1 = dtpicker1.Value.ToShortDateString
            dtdate2 = dtpicker2.Value.ToShortDateString

            'create a sqlcommand to represent the query

            cmd.CommandType = CommandType.Text
            cmd.CommandText = "select * from ActionManagement where Date >= '" & dtdate1 & "' and Date <= '" & dtdate2 & "'"
            'create a sqladapter to talk to the database
            Dim da As SqlDataAdapter = New SqlDataAdapter
            da.SelectCommand = cmd
            'create a dataset to hold the data
            Dim ds As DataSet = New DataSet
            'fill dataset with results
            da.Fill(ds, "Results")
            'bind the it to data grid
            dgResults.DataSource = ds
            dgResults.DataMember = "Results"
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 9 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 9 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros