Hello,
I have added 6th column to my access database table named as TblInvoice.
I am retrieving data from this column in text box named as TxtRefNo
My code is
The code is running well when it has some value, but it gives error when it has no value as -
"Conversion from string "Conversion from type 'DBNull' to" to type 'Integer' is not valid."
How to solve this ?
Thanks in advance.
I have added 6th column to my access database table named as TblInvoice.
I am retrieving data from this column in text box named as TxtRefNo
My code is
VB.NET:
Public Sub InvInfo()
con.Close()
con.Open()
str = "Select * from TblInvoice where InvoiceID=@id"
cmd = New OleDbCommand(str, con)
cmd.Parameters.AddWithValue("@id", TxtInvoiceID.Text)
Dim dr As OleDbDataReader = cmd.ExecuteReader()
Try
If dr.Read() Then
TxtRefNo.Text = dr.GetValue(6)
dr.Close()
End If
Catch ex As Exception
MsgBox("", ex.Message)
dr.Close()
Finally
con.Close()
End Try
End Sub
"Conversion from string "Conversion from type 'DBNull' to" to type 'Integer' is not valid."
How to solve this ?
Thanks in advance.