Showing posts with label getvalue. Show all posts
Showing posts with label getvalue. Show all posts

Wednesday, March 7, 2012

Invalid attempt to read when no data is present?

when execute

If IsDBNull(sqlreader.GetValue(i)) Then

Error info:Invalid attempt to read when no data is present

but i am sure there were records

Any ideas? Regards

Have you checked sqlreader.Read() is true?|||

it's ture,below is my code

For i = 1 To sqlreader.FieldCount - 1
If IsDBNull(sqlreader.GetValue(i)) = false Then
Row.fieldname = Trim(sqlreader.GetName(i).ToString())
Row.fieldvalue = Trim(sqlreader.GetString(i))
End If
Next

both fieldcount and getname are right