Assigning a null value to variables from non required fields

Discussion in 'ASP .Net Web Controls' started by Andy, May 7, 2004.

  1. Andy

    Andy Guest

    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
     
    Andy, May 7, 2004
    #1
    1. Advertising

  2. Andy

    Eidolon Guest

    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:...
    > 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
     
    Eidolon, May 7, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve Caliendo

    Assigning value to null

    Steve Caliendo, Jun 8, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    366
    Raterus
    Jun 8, 2004
  2. Tien
    Replies:
    1
    Views:
    462
    Martin Dechev
    Oct 22, 2004
  3. Replies:
    5
    Views:
    26,706
    Mike Schilling
    Mar 29, 2006
  4. Col
    Replies:
    1
    Views:
    628
    peter koch
    Apr 21, 2006
  5. weston
    Replies:
    1
    Views:
    253
    Richard Cornford
    Sep 22, 2006
Loading...

Share This Page