How Do I Get A RecordCount

Joined
Aug 3, 2002
Messages
19
Hey All,

I have a quick question... how do i get a count of how many records are selected when i execute a SELECT query...
like when it was in ADO with the use of .recordcount

How do i do this in ADO.net

Thanks
~John~
 
Doesnt the xxxDataReader class have a Count property? If not then doing an xxxCommand.ExecuteScalar on SELECT COUNT(*) FROM table is the only thing I can think of.
 
The datareader doesnot have a count property.

What you can do is that use a dataadapter and fill the results in a table by using the Fill method, and then count the rows of that table.

sample code
Dim da as new dataadapter("Select ....","Connection string")
dim dt as new datatable()
da.fill(dt)
dim recordcount as integer = dt.rows.count
Hope this helps...
 
ashrobo, if thats all youre doing with the data is looping through to count it youd likely do well by taking wyrds recommendation and letting the db do the count for you.
 
Back
Top