BlakeMcKenna
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:
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
Would this work?
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks...that worked!