|
-
Dec 13th, 2010, 03:20 PM
#1
Thread Starter
Fanatic Member
[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.
Last edited by Dubya007; Dec 13th, 2010 at 03:24 PM.
"...Men will still say THIS was our finest hour"
If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?
-
Dec 13th, 2010, 03:31 PM
#2
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
My usual boring signature: Nothing
 
-
Dec 13th, 2010, 03:57 PM
#3
Thread Starter
Fanatic Member
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
"...Men will still say THIS was our finest hour"
If a tree falls in the woods and no one is there to see it, do all the other trees make fun of it?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|