Null Values

Discussion in 'ASP .Net' started by Craig, Nov 1, 2004.

  1. Craig

    Craig Guest

    I have the following code in my code behind page for an apsx page...

    If Not IsDBNull(DataSet1.tblMyTable(1).MyField) Then
    'More Code
    End if

    It returns the following error - "Cannot get value because it is DBNull."

    I can't even test for DBNull without an error.

    How do I get around this?
     
    Craig, Nov 1, 2004
    #1
    1. Advertisements

  2. Craig

    Jarmo Muukka Guest

    You get the error because DataSet1.tblMyTable(1).MyField tries to cast the
    object to type of MyField, but it fails, because MyField is DBNull.Value.
    You use typed datasets, so you should use method call IsMyFieldNull() to
    check can you use the MyField or not.

    JMu

    "Craig" <> wrote in message
    news:...
    >I have the following code in my code behind page for an apsx page...
    >
    > If Not IsDBNull(DataSet1.tblMyTable(1).MyField) Then
    > 'More Code
    > End if
    >
    > It returns the following error - "Cannot get value because it is DBNull."
    >
    > I can't even test for DBNull without an error.
    >
    > How do I get around this?
    >
    >
     
    Jarmo Muukka, Nov 2, 2004
    #2
    1. Advertisements

  3. Craig

    Craig Guest

    Thanks. Good Clear Explanation!

    "Jarmo Muukka" <> wrote in message
    news:...
    > You get the error because DataSet1.tblMyTable(1).MyField tries to cast the
    > object to type of MyField, but it fails, because MyField is DBNull.Value.
    > You use typed datasets, so you should use method call IsMyFieldNull() to
    > check can you use the MyField or not.
    >
    > JMu
    >
    > "Craig" <> wrote in message
    > news:...
    > >I have the following code in my code behind page for an apsx page...
    > >
    > > If Not IsDBNull(DataSet1.tblMyTable(1).MyField) Then
    > > 'More Code
    > > End if
    > >
    > > It returns the following error - "Cannot get value because it is

    DBNull."
    > >
    > > I can't even test for DBNull without an error.
    > >
    > > How do I get around this?
    > >
    > >

    >
    >
     
    Craig, Nov 2, 2004
    #3
    1. Advertisements

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. Kivak Wolf
    Replies:
    2
    Views:
    10,275
    Kivak Wolf
    Jun 28, 2005
  2. vizlab
    Replies:
    3
    Views:
    4,494
    Michael Bar-Sinai
    Oct 17, 2007
  3. Replies:
    16
    Views:
    7,937
    Mike Schilling
    Oct 12, 2005
  4. Replies:
    5
    Views:
    30,018
    Mike Schilling
    Mar 29, 2006
  5. Bo Peng
    Replies:
    13
    Views:
    14,133
    Siemel Naran
    Jul 18, 2004
  6. Ken
    Replies:
    69
    Views:
    13,302
    Michael D. Borghardt
    Jul 31, 2004
  7. Ken
    Replies:
    5
    Views:
    2,808
    Victor Bazarov
    Jul 24, 2004
  8. Mathieu Malaterre

    delete NULL, what about delete[] NULL

    Mathieu Malaterre, Aug 17, 2004, in forum: C++
    Replies:
    2
    Views:
    4,065
    Mathieu Malaterre
    Aug 17, 2004
Loading...