Results 1 to 3 of 3

Thread: [RESOLVED] [2005] Error - Operator '=' is not defined for type 'DBNull' and string "Null".

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    216

    Resolved [RESOLVED] [2005] Error - Operator '=' is not defined for type 'DBNull' and string "Null".

    Operator '=' is not defined for type 'DBNull' and string "Null". Is the error I get

    With this command

    Code:
    If dataset.Tables(0).Rows(0).Item("Sub-Group") = "Null" Then
                Label8.Text = ("")
            Else
                Label8.Text = dataset.Tables(0).Rows(0).Item("Sub-Group")
            End If
    If the data is not null it works great. But if the data is Null I get that Error. Can anyone shed some light on the subject. Or maybe sugest a differnt way of checking.

    Btw its connecting to a sql 2005 server.

    thanks as always

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    104,990

    Re: [2005] Error - Operator '=' is not defined for type 'DBNull' and string "Null".

    The string "Null" is not a null value. It's a string containing four characters. If you want to determine whether a field in a DataRow contains a null value then you could do this:
    vb.net Code:
    1. If dataset.Tables(0).Rows(0).Item("Sub-Group") Is DBNull.Value Then
    That said, the DataRow class provides a method specifically for this purpose:
    vb.net Code:
    1. If dataset.Tables(0).Rows(0).IsNull("Sub-Group") Then
    Finally, it's worth noting that DBNull.ToString will return an empty string anyway. That means that, if you want to display an empty string for null values, you can simply do this:
    vb.net Code:
    1. Label8.Text = dataset.Tables(0).Rows(0).Item("Sub-Group").ToString()
    and there's no need for any If statements.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Dec 2007
    Posts
    216

    Re: [2005] Error - Operator '=' is not defined for type 'DBNull' and string "Null".

    I knew someone smart would know what it meant. Thanks a bunch. I am actaully have a case where I will need to do it both ways. So thanks a million.

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