SqlDataReader Item method not working

Iteria

New member
Joined
Jun 16, 2007
Messages
2
Programming Experience
Beginner
I keep getting a compiler error that tells me that I'm trying to access non-existent data. I ran the query in SQL Server and I received results back. In debugging mode I ran the HasRows method of sqlDataReader and it returned true, so I was definitely sure that there were rows being returned.

Still, whenever I ran dataReaderVariable.Item(someColumnIndexValue) or dataReaderVariable.Item("someKnownColumnName") I would get an error. I'm not really sure why I'm getting this error. There's no reason for it as there are rows being returned.

Here's the exact error, "Invalid attempt to read when no data is present."
 
Does SqlDataReader.Read method return True?
 
You know, I didn't even think about that method until now. Toying with it a little, I found that if I place a while loop with DataReader.read as the condition around my code, it works.

Thanks for giving me the idea.
 
Back
Top