Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 182
  • Last Modified:

How To check Null values

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
Ahmadal_najjar2003
Asked:
Ahmadal_najjar2003
3 Solutions
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
IsDBNull() function is what you need:

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

Open in new window

0
 
appariCommented:
if isnothing(MyAccID )

or

if MyAccID  = dbnull.value
0
 
Stephen MandersonSoftware EngineerCommented:
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
 
Ahmadal_najjar2003Author Commented:
Yes AngelIII, You touch the target.
Very good Functions from MrManderson.
And thanks to appari.
0
 
Ahmadal_najjar2003Author Commented:
Thanks To all.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now