Accessing oledb reader without moving to next record

J

John

Hi

How can I check if an oledb reader returned any records after ExecuteReader,
without fetching the next record?

Thanks

Regards
 
C

Cor Ligthert[MVP]

Hi John,

Use a Select string with a Count for the same "where" and use an
executescalar

Cor
 
W

William Vaughn MVP

MyDataReader.HasRows
Repeating the query with a Count? Excuse me? Repeat the whole query process
just to get a count? Expensive, unnecessary and inaccurate. What if a row is
added the instant after your "Count" query? Wrap them in a transaction? That
just slows down everyone else...

--
__________________________________________________________________________
William R. Vaughn
President and Founder Beta V Corporation
Author, Mentor, Dad, Grandpa
Microsoft MVP
(425) 556-9205 (Pacific time)
Hitchhiker’s Guide to Visual Studio and SQL Server (7th Edition)
http://betav.com http://betav.com/blog/billva
____________________________________________________________________________________________
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top