-
[RESOLVED] DBNull
I've been getting this error when pulling data from a recordset. It is coming from a null entry and as a newbie to VB2008 I'm not sure how to get around this.
here is my code
lblShipping.Text = reader("CARRIERCODE")
the error:
Conversion from type 'DBNull' to type 'String' is not valid.
Basically what i'm attempting to accomplish is to see if there is anything in that field. If so put it into the text box if not leave it blank.
-
Re: DBNull
That looks like a DataReader, which gives you other options. One thing you could do is something like:
Code:
If IsNull(reader("CARRIERCODE")) Then
'It is Null
End If
However, for a datareader, there is an alternative:
Code:
If reader.IsDBNull(reader.GetOrdinal("CARRIERCODE")) Then
-
Re: DBNull
That worked great! Thank you so much for the fast answer.
Here is my final Code.
Code:
If reader.IsDBNull(reader.GetOrdinal("CARRIERCODE")) Then
lblShipping.Text = ""
Else
lblShipping.Text = reader("CARRIERCODE")
End If