Solved

How To check Null values

Posted on 2008-06-20
5
171 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
5 Comments
 
LVL 142

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

910 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now