Checking if SqlDataReader contains data

  • Thread starter Thread starter relaxory
  • Start date Start date
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
 
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 )
{}
 
Superb! Thanks.. I guess I should have looked up .SqlDataReader.Read
Method before I post.

Thanks again.
 
Back
Top