Monday, August 16, 2010

How to count particular number of rows in a datagrid in Oledb?

A DataGrid is not OleDb - it is something you get way downstream from OleDb when you render the data to a Windows form or asp.net web page.





Are you sure you don't have access to this data prior to rendering it? It would be far easier to grab a DataView off of a DataTable and use that for counting, than trying to count rows in a user interface element...





A Windows Form DataGrid is much more iserializable style collection than an asp.net grid, and can be counted with an .Items.Count property or something close to that.How to count particular number of rows in a datagrid in Oledb?
The easiest thing to do is count the rows in the Data Source attached to the DataGrid.





If the source of your grid is a DataTable named DataTable1,





DataTable1.Rows.Count





If the source of your grid is a DataSet named DataSet1, and you want the count of the first DataTable inside it, use





DataSet1.Tables(0).Rows.Count

No comments:

Post a Comment