tags:

views:

511

answers:

2

It seems like IDataReader.Read() is always true at least one time (If I'm wrong about this let me know.) So how do you tell if it has no records without just wrapping it in a try/catch?

+3  A: 
if(dr.Read())
{
   //do stuff
}
else
{
 //it's empty
}

usually you'll do this though:

while(dr.Read())
{
}
Ben Scheirman
This is what I've tried, but it seems that the condition is always true at least once, but then if try to extract a value from the reader it throws an error.
JC Grubbs
+2  A: 

Yes, if you want to use the interface then Read until false is the only way to test. If you are looking for a generic IDataReader implementation, you could try DbDataReader and use the HasRows property.

KiwiBastard
DbDataReader is an abstract class
aku