objReader = strCMD.ExecuteReader
objReader.Read()
if objReader.IsDBNull(0) = true then...
If NULL/Empty, display no records found. If records are found, display "1 or more records have been found". I keep getting the error "Invalid attempt to read when no data is present". I'm not sure what I am doing wrong here.Do While objReader.Read()
' your code.
Loop|||Use the HasRows property of a DataReader:
objReader = strCMD.ExecuteReader
If objReader.HasRows() Then
' Display 1 or more rows found
Else
' Display no rows found
End If
The reason your code was failing was because the "objReader.Read()" line attempts to access the next element in the DataReader, and so if it's empty then it becomes an invalid access, like trying to access one more index past the end of an array. If all you need is whether or not the DataReader contains any information, then HasRows is your easiest bet.|||And if what you need to do is access the info datareader contains, and are getting this error, and have a do while loop, what's the next thing to try?|||Look at why the SQL isn't returning anything!
No comments:
Post a Comment