Solved

How To check Null values

Posted on 2008-06-20
5
174 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

Independent Software Vendors: 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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

756 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