?
Solved

Returning NULL Values and how to handle it?

Posted on 2014-03-06
4
Medium Priority
?
196 Views
Last Modified: 2014-03-07
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?
0
Comment
Question by:BlakeMcKenna
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 39910574
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.
0
 

Author Comment

by:BlakeMcKenna
ID: 39910684
In the case that I am using it for, it will always load the data into a variable be it string or numeric...
0
 
LVL 28

Accepted Solution

by:
Ark earned 2000 total points
ID: 39911531
Public Shared Function GetDBString(ByVal o As Object, Optional ByVal strDBNull As String = "") As String
    If o Is Nothing Then Return strDBNull
    If IsDBNull(o) Then Return strDBNull Else Return o.ToString
End Function

Open in new window


Using:
TextBox1.Text = GetDBString(myDataRow(fieldName), "Missing")

Open in new window

0
 

Author Closing Comment

by:BlakeMcKenna
ID: 39912542
Thanks...that worked!
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question