Question DataReader doesnt seem to retrieve the first row of data

darkcat02

Active member
Joined
Mar 4, 2009
Messages
38
Programming Experience
1-3
hi everyone,

i got a big problem over my datareader here...
it always display the second row...

any ideas?? i cant see any problem at all on my coding.... or maybe i cant find it...
 
You're probably doing a call to Read() BEFORE you start looping

Ensure that it goes like:

VB.NET:
reader = whatever.ExecuteReader()
While reader.Read()
  'loop
End While


Not like:

VB.NET:
reader = whatever.ExecuteReader()

If Not[B] reader.Read() [/B]Then Exit Sub '[B]this will advance the reader to first row[/B]

While reader.Read() 'starts looping from row 2!
  'loop
End While
 
You're probably doing a call to Read() BEFORE you start looping

Ensure that it goes like:

VB.NET:
reader = whatever.ExecuteReader()
While reader.Read()
  'loop
End While


Not like:

VB.NET:
reader = whatever.ExecuteReader()

If Not[B] reader.Read() [/B]Then Exit Sub '[B]this will advance the reader to first row[/B]

While reader.Read() 'starts looping from row 2!
  'loop
End While

hahaha.. thank you thank you.. now i see my error.. it was supposed to be reader.hasrows... but i mistakenly type reader.read()... thanks again! ^__^
 
I always thought HasRows was pointless, because if ther are no rows to start with, Read() returns false straight away, so a While Read() would never run the loop
 
Back
Top