Link to home
Start Free TrialLog in
Avatar of BlakeMcKenna
BlakeMcKennaFlag for United States of America

asked on

Returning NULL Values and how to handle it?

I know this is a Database 101 quesiton, but when I return a recordset from a DB Table and a column is NULL, what is the best way to handle it before loading the value into a control, such as a textbox?

I was thinking about just writing a routine like this:

    Public Function CheckForNULLs(ByVal fld As Object) As String
        Try
            If IsDBNull(fld) Then
                Return ""
            End If

        Catch ex As Exception
            EH.ErrorMessage = "CheckForNULLs() - " & ex.Message & "...Contact Engineering!" & "~E"
        End Try
    End Function

Open in new window

Would this work?
Avatar of kaufmed
kaufmed
Flag of United States of America image

The "best way to handle it" is going to depend on your business need and your code structure. You may have a convention whereby you use null as a sentinel value; or you may want to set the property to some default value if it comes back from the DB as null.
Avatar of BlakeMcKenna

ASKER

In the case that I am using it for, it will always load the data into a variable be it string or numeric...
ASKER CERTIFIED SOLUTION
Avatar of Ark
Ark
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks...that worked!