Reputation: 271
How can I count how many rows are returned by a dataset and then show the total number of rows as textbox.text and read-only so that the user can only see them but not change them?
so far I have this but it dosent return a number and says it cant find table 0:
tbRecordsFound.Text = ds.Tables(0).Rows.Count
Upvotes: 0
Views: 77353
Reputation: 65
tbRecordsFound.Text = ds.Tables(0).Rows.Count
The above code will work, however you need to give the table an identifier, such as:
tbRecordsFound.Text = ds.Tables("TableName").Rows.Count
This can be done via creating a DataAdapter and using the "Fill" function to give the table a name. Here is an example where "da" represents the DataAdapter:
da.Fill(ds, "TableName")
Upvotes: 1
Reputation: 21
For i As Integer = 0 To yourdatagridviewName.Rows.Count() - 1 Step +1
i = +i
TextBox2.Text = i
Next
Upvotes: 0
Reputation: 46057
Try something like this:
tbRecordsFound.Text = ds.Tables.Cast<DataTable>().Sum(x => x.Rows.Count).ToString()
You can also do it like this:
Dim recordCount as Integer = 0;
For Each table as Datatable in ds.Tables
recordCount += table.Rows.Count
tbRecordsFound.Text = recordCount.ToString()
Upvotes: 4