CHECK FOR NULL IN VB

24746
5
09-20-2010 11:23 AM
DonJohnson
New Contributor
I am trying to identify a NULL value in a string field and assign a value. 

IsNull = True is causing an error. 

Any other suggestions?
0 Kudos
5 Replies
NeilClemmons
Regular Contributor III
The following is VB.NET.

    Public Shared Function GetStringValue(ByVal value As Object) As String
        If value Is DBNull.Value Then
            Return String.Empty
        Else
            Return Convert.ToString(value)
        End If
    End Function
0 Kudos
DonJohnson
New Contributor
I am using ModelBuilder and have the following:

Dim ROAD as String
ROAD = [ROAD_NAME]

if isNull(ROAD) = True then
ROAD = "NONE"
End If
0 Kudos
JamesCrandall
MVP Frequent Contributor
Not familiar with ModelBuilder, but the VB.NET function to check for null values is the IsDBNull function.  Maybe something like this? (although I am not sure about getting/setting your "[ROAD_NAME]" value):

Dim ROAD As String
If Not IsDBNull([ROAD_NAME]) Then
  ROAD = [ROAD_NAME]
Else
  ROAD = "NONE"
End If

I am using ModelBuilder and have the following:

Dim ROAD as String
ROAD = [ROAD_NAME]

if isNull(ROAD) = True then
ROAD = "NONE"
End If
0 Kudos
JohnHauck
Occasional Contributor II
Please use the following:

Dim ROAD as String
If IsNull( [ROAD_NAME]) Then
ROAD = "NONE"
Else
ROAD = [ROAD_NAME]
End If
0 Kudos
EllenTejan
New Contributor
Thank you don

I imbeded

isNull(ROAD) = True

into  my expression and it worked for me.

Ellen
0 Kudos