What we did was to write a function which checks for nulls, and returns a
passed in value if the checked value is null... similar to the NVL function
in ORACLE. Here is the code for it:
Public Function NVL(ByVal Arg As Object, ByVal NullValue As Object) As
Object
If IsDBNull(Arg) Then
Return NullValue
Else
Return Arg
End If
End Function
I believe the module needs System.Data imported (or using'ed if your in C#).
Then this way anytime we have a field which Might be null and could foul
things up, instead of assigning its value directly, we NVL it as so:
OLD:
txtPhone.Text = myDataTable.Rows(4)("PHONE")
NEW:
txtPhone.Text = NVL(myDataTable.Rows(4)("PHONE"),"")
Now whenever i assign the Text property, if the field is null, the text just
gets set to String.Empty.
Hope this helps.
Andy said:
I am creating a web app that has a panel that is only visible under
certain circumstances. In the panel are many textbox fields that are
strings, integers and dates. The problem I am having is when this panel is
not visible and the fields are not used, I am getting errors saying that it
cannot assign a null value to my variables. Is there anyway to get around
this?