Solved

How To check Null values

Posted on 2008-06-20
5
176 Views
Last Modified: 2010-04-23
I retrieve value from a database and save it in a variable , How Can I check if it is null value

Dim MyAccID As Integer = BillMasterTable.Rows(0).Item("AccID")

If MyAccID is Null  ' How To do that
0
Comment
Question by:Ahmadal_najjar2003
[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
5 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 350 total points
ID: 21831856
IsDBNull() function is what you need:

if IsDBNull (BillMasterTable.Rows(0).Item("AccID")) Then
  ...

Open in new window

0
 
LVL 39

Assisted Solution

by:appari
appari earned 50 total points
ID: 21831864
if isnothing(MyAccID )

or

if MyAccID  = dbnull.value
0
 
LVL 19

Assisted Solution

by:Stephen Manderson
Stephen Manderson earned 100 total points
ID: 21831901
If you are trying to trap errors when loading from a db this is how I do it.

I.e
Dim MyAccID As Integer = CheckForNullInteger(BillMasterTable.Rows(0).Item("AccID"))

    Public Function CheckForNullInteger(ByVal Value As Object) As Integer
        If Value Is System.DBNull.Value Then
        Else
            Return Value
        End If
    End Function
 
    Public Function CheckForNullDate(ByVal Value As Object) As DateTime
        If Value Is System.DBNull.Value Then
        Else
            Return Value
        End If
    End Function
 
    Public Function CheckForNullString(ByVal Value As Object) As String
        If Value Is System.DBNull.Value Then
            Return ""
        Else
            Return Value
        End If
    End Function

Open in new window

0
 

Author Comment

by:Ahmadal_najjar2003
ID: 21832066
Yes AngelIII, You touch the target.
Very good Functions from MrManderson.
And thanks to appari.
0
 

Author Closing Comment

by:Ahmadal_najjar2003
ID: 31469178
Thanks To all.
0

Featured Post

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!

Question has a verified solution.

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

Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

626 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