Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


How to check for NULL Values

Posted on 2005-03-01
Medium Priority
Last Modified: 2012-06-22
What is the best way to check for bull values. I dont want to covert to string if data is null is there a function i can use

cboOriginalCurrency.Value = CType(dtPaymentHeader.Rows(0)(prsgpaymentheader.Columns.vchOriginalCurrency), String)
Question by:anwarmir
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
LVL 25

Expert Comment

ID: 13429779
isdbnull(object) ? what do you want to do if the value is dbnull
LVL 25

Expert Comment

ID: 13429815
or like

cboOriginalCurrency.Value = iff(isdbnull(dtPaymentHeader.Rows(0)(prsgpaymentheader.Columns.vchOriginalCurrency), "nullvalue",CType(dtPaymentHeader.Rows(0)(prsgpaymentheader.Columns.vchOriginalCurrency), String))


Author Comment

ID: 13430506
id the object is null or empty string then i dont want to do anything....Our standards wont let us use backward compatible functions like IIF
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 25

Expert Comment

ID: 13430527
then just do

if not isdbnull(dtPaymentHeader.Rows(0)(prsgpaymentheader.Columns.vchOriginalCurrency)) then
   cboOriginalCurrency.Value = CType(dtPaymentHeader.Rows(0)(prsgpaymentheader.Columns.vchOriginalCurrency), String)
end if

Author Comment

ID: 13430899
i'm getting isDbNull not declared d o i have to declare it with imports or something?
LVL 28

Accepted Solution

iboutchkine earned 1000 total points
ID: 13431437
fro example you want to check if X is null

if x Is Sytem.DBNull.VAlue then...

Expert Comment

ID: 13472522
i had this same problem this is a function that if the value is null replace it with a certain value based on its data type

Public Function cNull(ByVal objData As Object, ByVal objType As String) As Object
        If IsDBNull(objData) Then
            Select Case objType
                Case "Boolean"
                    Return False
                Case "DateTime"
                    Return DateTime.MinValue
                Case "Decimal", "Double", "Integer", "Long", "Short", "Single"
                    Return 0
                Case "String"
                    Return String.Empty
            End Select
            Return objData
        End If
    End Function

to use the function correctly here is an example

Dim myWidth As Integer= cNull(myDvRow("bldg_width"), "Integer")
Dim myDoor As Double = cNull(myDvRow("door_height"), "Double")
Dim myActive As Boolean = cNull(myDvRow("active_flag"), "Boolean")

etc... i hope this helps also if u put that function in a module u can use it on any form in ur project

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

721 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