DBNULL

  • I have a stored procedure that pulls data from three different tables. I am using a LEFT JOIN because not all three tables have data for every user.

    On my asp.net page I am using an if statement to determine if a panel is visible or not based on data from one of the tables. When the value is null I get the:

    Operator is not valid for type 'DBNull' and type 'Integer'.

    error message

    Is there a way to test if the value is null and then convert it to a 0?

    If CISCreated = 1 Then

    ClientCIS = cmdSelect.ExecuteReader()

    If the value is 1 I am adding a few values to the session.

  • Have you tried using the IsNull function ?!







    **ASCII stupid question, get a stupid ANSI !!!**

  • That would have to be in your Stored Procedure. And IsNull will rely on data actually being returned. Could you post what the output looks like for the data and if there is no row does Null actually return?

  • Here's an example...

    SELECT ISNULL(CISCreated, 0) FROM Table will replace all Nulls with zeroes







    **ASCII stupid question, get a stupid ANSI !!!**

  • I did end up doing the isnull in my stored procedure and it fixed the problem.

  • Great!







    **ASCII stupid question, get a stupid ANSI !!!**

  • Wouldn't this ASP.NET code work as well?  Though it may be better practice to let your server do more of the work, as you have done already.

    If (Not IsNull(rsSomething("CISCreated")) Then ...

    So long, and thanks for all the fish,

    Russell Shilling, MCDBA, MCSA 2K3, MCSE 2K3

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply