Results 1 to 7 of 7

Thread: test for null

  1. #1

    Thread Starter
    Addicted Member Halon's Avatar
    Join Date
    Oct 2002
    Location
    under desk choking on rage
    Posts
    228

    test for null

    Anyone know how to test for a null value being returned from a database query

    i tried the code below but think i had too much beer over the long weekend because it should be easy but i can't locate the middle portion of my brain

    Code:
    If myDataSet.Tables(0).Rows(0).Item("Contact") Is Not System.DBNull Then
                contactTemp = ""
            End If
    thanks for any help
    Soylent Green tastes like chicken

  2. #2
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    do a search on the IsDBNull Function
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

  3. #3
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    DbNull.Value
    It's tough being an unhandled exception...

    ___________
    VB.NET 2008
    VB.NET 2010
    ORACLE 11g
    CRYSTAL 11

  4. #4
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    You need to understand that DBNull is very different from empty string (""). Numeric fields for example can be DBNull but cannot be "". Also a lot of controls will choke if you are trying to stick datarow fields into them if the field is DBNull, but will work fine if it is "".

  5. #5
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Use IsNull function existed in the Rows Obj . Something like this :
    VB Code:
    1. If ds.Tables(0).Rows(0).IsNull(0) Then

  6. #6
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    VB Code:
    1. If myDataSet.Tables(0).Rows(0).Item("Contact")  Is DBNull.Value Then
    2. 'you have a null value

  7. #7

    Thread Starter
    Addicted Member Halon's Avatar
    Join Date
    Oct 2002
    Location
    under desk choking on rage
    Posts
    228
    Thanks for the help everyone!
    nemaroller ... used yours and worked like a charm

    Soylent Green tastes like chicken

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width