1

I have the code below:

 Dim ds As New DataSet
 Dim sda As System.Data.SqlClient.SqlDataAdapter
 Dim sSQL As String
 Dim strCon As String

 sSQL = " .... MY QUERY HERE .... "

 strCon = appBase.dbConnString

 sda = New System.Data.SqlClient.SqlDataAdapter(sSQL, strCon)
 sda.Fill(ds, "MY TABLE FROM DB")


 dgRecordsContent.DataSource = ds.Tables("MY TABLE FROM DB")
 dgRecordsContent.DataBind()

 dgRecordsContent.Visible = True

 dbConn.Close()

How can I programatically count the number of rows from the datagrid that I'm showing the values in?

1
  • 1
    Fill is a method returning the number of rows Commented Dec 10, 2015 at 18:23

3 Answers 3

1

Provided that the DataTable being filled doesn't already contain any rows, you can get the count using:

int count = sda.Fill(ds, "MY TABLE FROM DB")

Otherwise you can access the rows in the DataTable using:

int count = ds.Tables("MY TABLE FROM DB").Rows.Count
Sign up to request clarification or add additional context in comments.

Comments

0

you can use ds.Tables[0].Rows.Count

Comments

0
 Dim ds As New DataSet
 Dim sda As System.Data.SqlClient.SqlDataAdapter
 Dim sSQL As String
 Dim strCon As String

 sSQL = " .... MY QUERY HERE .... "

 strCon = appBase.dbConnString

 sda = New System.Data.SqlClient.SqlDataAdapter(sSQL, strCon)
 Dim num_rows=sda.Fill(ds, "MY TABLE FROM DB")

 MessageBox.Show(num_rows.ToString())  

 dgRecordsContent.DataSource = ds.Tables("MY TABLE FROM DB")
 dgRecordsContent.DataBind()

 dgRecordsContent.Visible = True

 dbConn.Close()  

Please Check This Edit @Emi

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.