Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Assigning a null value to variables from non required fields

Reply
Thread Tools

Assigning a null value to variables from non required fields

 
 
Andy
Guest
Posts: n/a
 
      05-07-2004
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
 
Reply With Quote
 
 
 
 
Eidolon
Guest
Posts: n/a
 
      05-07-2004
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" <> wrote in message
news:489D6CAE-059A-4723-A963-...
> 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



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Assigning methods to objects, and assigning onreadystatechange to an XMLHttpRequest -- an inconsistency? weston Javascript 1 09-22-2006 09:33 AM
Begin() applied on empty Vector returns NULL or non null value???? Col C++ 1 04-21-2006 01:12 PM
"stringObj == null" vs "stringObj.equals(null)", for null check?? qazmlp1209@rediffmail.com Java 5 03-29-2006 10:37 PM
How to validate non-required fields? Tien ASP .Net 1 10-22-2004 09:06 AM
Assigning value to null Steve Caliendo ASP .Net 1 06-08-2004 04:41 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57