Nulls.net: Invalid use of Null Error : use, null, invalid, error :)

Prevent Invalid Use of Null Error

If you are reading data from a database regardless of which programming language that you use, you will invariably run into a database that is designed to allow null values to be saved in table fields. If you are unfamiliar with the database design (and trust me this can happen) you will want to prevent any untimely errors due to trying to assign a Null value to a variable when reading the data in. Here are the simple steps to avoid this issue.

1
Create a string variable.
Dim strTemp as String = “” ‘this is how it would be done in VB.net
2
When reading the data point in join it with a zero length string.

“” & rs!FieldName
3
Enclose step two inside parenthesis.

(“” & rs!FieldName)
4
assign to string variable.

strTemp = (“” & rs!FieldName)
5
There are many variations that this can be done, but this gives you the basics to get started.

Most, if not all, programming languages read from left to right and follow the PEMDAS mathematical rule. So in our example if will perform what is in the parenthesis first by reading from left to right and join a zero length string to whatever the fieldname is.


Most Related Posts

You must be logged in to post a comment.


htcell