System.DBNULL is a type and cannot be used by an expression

Discussion in 'Databases' started by Scott, Jul 4, 2005.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Try using:
    If rs.Fields(5).ToString = '' Then
     
  2. Hi!

    I am using VB.NET and a Firebird SQL Server database.

    My query gives null values.
    I need to check if the value i'm getting back is null. I do it like this :
    -----------------------------------------------------------------




    If rs.Fields(5).Value = System.DBNull.Value Then


    TextBox6.Text = "NOT AVAILABLE"


    Else


    TextBox6.Text = rs.Fields(5).Value


    End If


    ----------------------------------------------------------------------------


    Then I get this error :


    Operator '=' is not defined for types 'System.Object' and 'System.DBNULL'. Use 'ls' operator to compare two refrence types.


    Then when I do this :


    ---------------------------------------------------------------------------





    If rs.Fields(5).Valuels System.DBNull.Value Then


    TextBox6.Text = "NOT AVAILABLE"


    Else


    TextBox6.Text = rs.Fields(5).Value


    End If


    ----------------------------------------------------------------------------


    I get this error :


    End of statement expected


    =-=-= Maybe I just don't know how to use the ls operator but please help me out with this.


    I really need to get an answer
     
  3. If you want to compare against DBNull, do this:

    If rs.Fields(5).Value.GetType() = typeof(System.DBNull)
     
  4. Simplest method is to use IsDBNull:


    If IsDBNull(rs.Fields(5).Value) Then


    TextBox6.Text = "NOT AVAILABLE"


    Else


    TextBox6.Text = rs.Fields(5).Value


    End If
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page