Solved

How To check Null values

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 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

9 Experts available now in Live!

Get 1:1 Help Now