Solved

How To check Null values

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

810 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