records returned from datareader error

  • Thread starter Thread starter Davef
  • Start date Start date
D

Davef

I get an error at: If IsDBNull(dr2("tax")) Then
if there are no records returned. How can I deal with that?


Dim dr2 As SqlDataReader = Salestax.GetMachSalesTax(SalesCookieID)
dr2.Read()
If IsDBNull(dr2("tax")) Then
taxPercent.Value = "0"
Else
taxPercent.Value = dr2("tax")
End If

Dim dr As SqlDataReader =
myCommand.ExecuteReader(CommandBehavior.CloseConnection)

' Return the datareader

Return dr


--

______________________
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)
______________________
 
Your code should be something like this

Dim dr2 As SqlDataReader = Salestax.GetMachSalesTax
(SalesCookieID)
if dr2.Read() then
If IsDBNull(dr2("tax")) Then
taxPercent.Value = "0"
Else
taxPercent.Value = dr2("tax")
End If
Else
' No records found
End if


' Return the datareader
 
Back
Top