asp-classicnulladodb

ASP Classic check for database NULL value in Recordset


I'm getting an ADODB Recordset and I need to check the value of a nullable column in ASP Classic. How can I tell whether it's null? AFAIK IsDBNull doesn't exist in ASP Classic, and all the Null testers ask whether the object is null, not its value.

E.g., I have Recordset RS that contains a column RS("myCol"). In the database, myCol is a nullable bit, so values can be {0, 1, NULL}.

How can I test RS("myCol") = NULL? It appears that if I literally run that comparison it will only tell me whether the object RS("myCol") is Null, not whether the value of the field requested is "database" null.


Solution

  • Try this, it should work if you are using MS SQL

    IF IsNull(RS("myCol")) = False THEN
      IF RS("myCol") THEN
        Response.Write "myCol is TRUE"
      ELSE
        Response.Write "myCol is False"
      END IF
    ELSE
      Response.Write "myCol is NULL"
    END IF
    

    or Try Using

    IF RS("myCol")<>"" THEN
      IF RS("myCol") THEN
        Response.Write "myCol is TRUE"
      ELSE
        Response.Write "myCol is False"
      END IF
    ELSE
      Response.Write "myCol is NULL"
    END IF