Home All Groups Group Topic Archive Search About

Accessing oledb reader without moving to next record

Author
7 Jun 2009 10:28 PM
John
Hi

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

Thanks

Regards

Author
8 Jun 2009 5:47 AM
Cor Ligthert[MVP]
Hi John,

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

Cor

Show quoteHide quote
"John" <info@nospam.infovis.co.uk> wrote in message
news:eDmqS975JHA.4404@TK2MSFTNGP04.phx.gbl...
> Hi
>
> How can I check if an oledb reader returned any records after
> ExecuteReader, without fetching the next record?
>
> Thanks
>
> Regards
>
Author
8 Jun 2009 3:51 PM
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
____________________________________________________________________________________________



Show quoteHide quote
"John" <info@nospam.infovis.co.uk> wrote in message
news:eDmqS975JHA.4404@TK2MSFTNGP04.phx.gbl...
> Hi
>
> How can I check if an oledb reader returned any records after
> ExecuteReader, without fetching the next record?
>
> Thanks
>
> Regards
>