Checking if SqlDataReader contains data

R

relaxory

If I'm doing a select WHERE' searching for a string... What is the best
way to condition a response based on whether the datareader contains
data or not?

while (myReader.Read()) {
if myReader.GetInt32(0) = 0

..

Something like that? Isn't there something that can return a bool?

Cheers
 
V

Vadym Stetsyak

if the query returned smth myReader.Read() will be equal to true.

if you always obtain some result, but want to check specific column you can
check it like
if ( reader["myColumnName"] == null )
{}
 
R

relaxory

Superb! Thanks.. I guess I should have looked up .SqlDataReader.Read
Method before I post.

Thanks again.
 

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