How to test for Null values in ADODB recordset in VB.Net RRS feed

  • Pytanie

  • What is the easiest way to test for a Null value in an ADODB recordset when using VB.Net.

    The IsNull function does not work in VB.Net, or so it seems.



    piątek, 15 września 2006 16:09


Wszystkie odpowiedzi

  • I believe it should be DBNull.Value

    Even though to you and me its still "null" - its a different type value meaning pretty much the same thing generally

    does this help?

    piątek, 15 września 2006 16:21
  • I tried it as follows

    Dim nulltest as DBNull

    nulltest = DBNull.Value

    if rs.fields("Tonne").value = nulltest then

    but I get the following error

    Operator '=' not defined for types System.DBNull and Object

    piątek, 15 września 2006 16:44
  • yes you can't do that. It should be:


    if rs.fields("Tonne").Value = DBNull.Value then

       'whatever here

    end if

    piątek, 15 września 2006 17:00
  • IsDBNull() replaces the isNull function in VB

    piątek, 15 września 2006 17:11
  • probably uses DBNull.Value in the function ;-)
    piątek, 15 września 2006 17:22

    If ( Not Convert.IsDBNull( dr("FirstName") ) ) Then

    Me._firstName = Cstr( dr("FirstName") )

    End If

    czwartek, 23 sierpnia 2007 20:48
  • Fuc...g  AWESOME  Udhai....
    • Zaproponowany jako odpowiedź przez Cyber Ghost wtorek, 4 sierpnia 2009 20:15
    środa, 25 marca 2009 08:56
  • Ok , took me a while to get logged on here but here is the best way of doing it.

    Dim NULL as System.DBNull = System.DBNull.Value

    name = iif(rs(0).value is null,"Unknown",rs(0).value)


    qty = iif(rs(1).value is NULL ,0,rs(1).value)

    this can also be done replacing the rs(0).value with the name of the actual field as indicated above "FirstName"

    This way, the value returned will always be validated against a null value, and in such event, the null value will then be replaced by "Unknown" or 0 but in the event of there not being a null value, the actual value will be returned.


    sorry for the late reply


    wtorek, 4 sierpnia 2009 20:21
  • handling dbnull in vb.net - full source code





    środa, 14 września 2011 16:36
  • this work for me:


    czwartek, 4 października 2018 17:18