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. Advertising

  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. Advertising

  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. 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. Kivak Wolf
    Replies:
    2
    Views:
    10,057
    Kivak Wolf
    Jun 28, 2005
  2. vizlab
    Replies:
    3
    Views:
    4,170
    Michael Bar-Sinai
    Oct 17, 2007
  3. Replies:
    16
    Views:
    7,282
    Mike Schilling
    Oct 12, 2005
  4. Replies:
    5
    Views:
    26,476
    Mike Schilling
    Mar 29, 2006
  5. Bo Peng
    Replies:
    13
    Views:
    13,260
    Siemel Naran
    Jul 18, 2004
Loading...

Share This Page