ASP Classic / ADODB / Null Issues

  • 8 years ago
    I'm trying to deal with values in my dataset which are set to null.
    Using VBScript, i've tried the following but I get an exception thrown:

    72: If objRecordSet("AccountNumber") <> ""
    73: Then Response.Write "" & objRecordSet("AccountNumber") & ""
    74: Else Response.Write " "
    75: End If

    Error Type:
    (0x80020009)
    Exception occurred.
    /folder/XXXX.asp, line 72

    Or if i try the following an exception is also thrown
    72: If objRecordSet("AccountNumber") Is Nothing
    73: Then Response.Write " "
    74: Else Response.Write "" & objRecordSet("AccountNumber") & ""
    75: End If

    Error Type:
    (0x80020009)
    Exception occurred.
    /folder/XXXX.asp, line 74

    Any ideas?

    TIA
    Matt
  • 8 years ago

    72: If objRecordSet("AccountNumber") <> ""
    73: Then Response.Write "" & objRecordSet("AccountNumber") & ""
    74: Else Response.Write " "
    75: End If


    You really didn't show enough of your code to see where you maybe making mistakes. I guess you are checking to make sure that there is something in your record set with eof. and you are not closing the recordset before you get to line 72. Also is this If statement inside of a loop? Anyway try this


    If IsNull(objRecordSet.fields("AccountNumber").value) = False Then
    Response.Write(objRecordSet("AccountNumber"))
    Else
    Response.Write("The field value for AccountNumber is empit")
    End If


    Edit: Sorry for got to close my IsNull()

  • 8 years ago

    Many thanks, that was just the answer I needed.


    Matt

  • 8 years ago


    If objRecordSet("AccountNumber") = null Then
       Response.Write "" & objRecordSet("AccountNumber") & ""
    Else
       Response.Write " "
    End If

    OR

    If isnull(objRecordSet("AccountNumber")) Then
       Response.Write "" & objRecordSet("AccountNumber") & ""
    Else
       Response.Write " "
    End If

    OR

    If not isnull(objRecordSet("AccountNumber")) or objRecordSet("AccountNumber") <> "" Then
       Response.Write "" & objRecordSet("AccountNumber") & ""
    Else
       Response.Write " "
    End If

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The difference between theory and practice is smaller in theory than in practice.”