Invalid attempt to read when no data is present.

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)
______________________
 
M

Marina

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!!!
 
M

Marina

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
 
M

Marina

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top