Assigning a null value to variables from non required fields

A

Andy

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

Any help is appreciated

Thanks
 
E

Eidolon

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top