How do one test for nulls in VB?

R

Randy Galliano

Hello,

I am reading some records into a recordset when I got to assign a text
box the value of one of the fields I get an exception because the
recordset has a null value in it. How do you test for nulls in vb script?

Example:

txtModel.Text = SqlDataReader("Manufacturer") '
Manufacturer is null.

Regards,

Randy.
 
J

Juan T. Llibre

If IsDBNull(SqlDataReader("Manufacturer")) Then
txtModel.Text = "N/A"
Else
txtModel.Text = SqlDataReader("Manufacturer")
End If
 
R

Randy Galliano

Randy said:
Hello,

I am reading some records into a recordset when I got to assign a text
box the value of one of the fields I get an exception because the
recordset has a null value in it. How do you test for nulls in vb script?

Example:

txtModel.Text = SqlDataReader("Manufacturer") ' Manufacturer
is null.

Regards,

Randy.


Let me clarify one more thing. I am using .net 2.0 with vb script.
According to the manual on MSDN isNull is a function I can use, but
Visual Studio is saying the function is not defined.

Regards,

Randy.
 
M

Mark Rae [MVP]

Randy Galliano said:
Hello,

I am reading some records into a recordset when I got to assign a text box
the value of one of the fields I get an exception because the recordset
has a null value in it. How do you test for nulls in vb script?

Example:

txtModel.Text = SqlDataReader("Manufacturer") ' Manufacturer
is null.

Regards,

Randy.
 
Joined
Oct 17, 2007
Messages
7
Reaction score
0
You will have to use something like this
if (SqlDataReader("Manufacturer") = DBNull.value) then
Do whatever for null handling
else
Assign things
end if

Regards,
UrStop
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top