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
2008-09-09 02:14:40
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
2008-09-09 02:20:36
+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
2008-09-09 02:15:31