How do one test for nulls in VB?

Discussion in 'ASP .Net' started by Randy Galliano, Nov 13, 2007.

  1. 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.
     
    Randy Galliano, Nov 13, 2007
    #1
    1. Advertising

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



    Juan T. Llibre, asp.net MVP
    asp.net faq : http://asp.net.do/faq/
    foros de asp.net, en espaƱol : http://asp.net.do/foros/
    ======================================
    "Randy Galliano" <> wrote in message news:%...
    > 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.
     
    Juan T. Llibre, Nov 13, 2007
    #2
    1. Advertising

  3. Randy Galliano wrote:
    > 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.
     
    Randy Galliano, Nov 13, 2007
    #3
  4. "Randy Galliano" <> wrote in message
    news:%...
    > 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.




    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Nov 13, 2007
    #4
  5. "Randy Galliano" <> wrote in message
    news:%...

    > How do you test for nulls in vb script?


    Assuming that you don't actually mean VBScript, you test for the field being
    DbNull.Value...


    --
    Mark Rae
    ASP.NET MVP
    http://www.markrae.net
     
    Mark Rae [MVP], Nov 13, 2007
    #5
  6. Randy Galliano

    urstop

    Joined:
    Oct 17, 2007
    Messages:
    7
    Location:
    London
    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
     
    urstop, Nov 14, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bob

    Problem with nulls

    Bob, Jul 2, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    336
  2. Bill

    Inputting NULLS?

    Bill, Dec 11, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    375
    Suresh
    Dec 11, 2003
  3. Mike

    allow NULLS

    Mike, Jun 20, 2004, in forum: ASP .Net
    Replies:
    8
    Views:
    606
    [MSFT]
    Jun 22, 2004
  4. Angela

    Dealing with NULLs

    Angela, Jun 23, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    401
    Patrice
    Jun 23, 2004
  5. Skybuck Flying

    Call oddities: &Test() vs &Test vs Test

    Skybuck Flying, Oct 4, 2009, in forum: C Programming
    Replies:
    1
    Views:
    762
    Skybuck Flying
    Oct 4, 2009
Loading...

Share This Page