Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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~

Posted
Doesn't 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.
Gamer extraordinaire. Programmer wannabe.
Posted

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...

Dream as if you'll live forever, live as if you'll die today
  • Leaders
Posted
ashrobo, if that's all you're doing with the data is looping through to count it you'd likely do well by taking wyrd's recommendation and letting the db do the count for you.
--tim

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...