Invalid attempt to read when no data is present.

  • Thread starter Thread starter Helixpoint
  • Start date Start date
H

Helixpoint

Dim dr1 As SqlDataReader = MachCodeListID.GetSingleMachCode(thecodesID)

' Read first row from database

dr1.Read()

If IsDBNull(dr1("CATNUM")) Then '**************** This is where I am getting
the error??????

thecatnum = 0

Else

thecatnum = dr1("CATNUM")

End If


--

______________________
David Fetrow
HelixPoint LLC.
http://www.helixpoint.com
(e-mail address removed)

Interested in Affordable Email Marketing?
Check out the HelixMailer at http://www.helixpoint.com/helixmailer.asp
If you are interested in becoming a Reseller of HelixPoint products, contact
(e-mail address removed)
______________________
 
If there was no row returned, there is now way to check if a column in that
row is null - because there is no row in the first place!!!
 
There is no point to doing that. dr1.Read returned false - hence no rows.
Neither of these things will work. The structure needs to be

If dr1.Read() Then

If IsDbNull(dr1("Catnum") Then
.....
End If

End If
 
No, my point is you could not do anything that would mean getting the column
value from the datareader.

The mere call to dr1("catnum") raises the error. There is no row - so no
column value for "catnum" - because there is no row!!

That's why the if statement for dr1.Read - to make sure there is a row
before you try to look at one of its columns.
 
Back
Top