Error with DBNull

Discussion in 'ASP .Net' started by Filipe Cristóvão, Sep 1, 2004.

  1. Hi,
    I know that this is a newbie's question, but I need to know how i do to know
    if a field in a table is DBNull.
    If I try to write (with response.write) the field, it gives me an error:
    "Cast from type 'DBNull' to type 'String' is not valid".
    Thanks for any help.

    --

    Filipe Cristóvão
     
    Filipe Cristóvão, Sep 1, 2004
    #1
    1. Advertising

  2. Filipe Cristóvão

    Hans Kesting Guest

    "Filipe Cristóvão" <> wrote in message news:...
    > Hi,
    > I know that this is a newbie's question, but I need to know how i do to know
    > if a field in a table is DBNull.
    > If I try to write (with response.write) the field, it gives me an error:
    > "Cast from type 'DBNull' to type 'String' is not valid".
    > Thanks for any help.
    >
    > --
    >
    > Filipe Cristóvão
    >
    >


    Various options:
    * You can test against DBNull.Value (if (myDataRow["field"] == DBNull.Value) ... )
    * DataRow has an IsNull(..) method to check a specific column in that row
    * Don't cast to string, but use the ToString() method, DBNull gives an empty string

    Hans Kesting
     
    Hans Kesting, Sep 1, 2004
    #2
    1. Advertising

  3. Tks for the help.
    I relly needed to know it.

    --

    Filipe Cristóvão

    "Hans Kesting" <> escreveu na mensagem
    news:%23%...
    >
    > "Filipe Cristóvão" <> wrote in message

    news:...
    > > Hi,
    > > I know that this is a newbie's question, but I need to know how i do to

    know
    > > if a field in a table is DBNull.
    > > If I try to write (with response.write) the field, it gives me an error:
    > > "Cast from type 'DBNull' to type 'String' is not valid".
    > > Thanks for any help.
    > >
    > > --
    > >
    > > Filipe Cristóvão
    > >
    > >

    >
    > Various options:
    > * You can test against DBNull.Value (if (myDataRow["field"] ==

    DBNull.Value) ... )
    > * DataRow has an IsNull(..) method to check a specific column in that row
    > * Don't cast to string, but use the ToString() method, DBNull gives an

    empty string
    >
    > Hans Kesting
    >
    >
     
    Filipe Cristóvão, Sep 1, 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. Ravikanth[MVP]
    Replies:
    6
    Views:
    3,895
    Aemca
    Jul 18, 2003
  2. Boris Zakharin

    Adding a DBNull value to the database

    Boris Zakharin, Aug 27, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    389
    Boris Zakharin
    Aug 27, 2003
  3. Martin
    Replies:
    2
    Views:
    433
    Martin
    Feb 2, 2004
  4. =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?=

    check for dbNull is throwing an error

    =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?=, Jan 16, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    3,809
    =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?=
    Jan 16, 2006
  5. Rob
    Replies:
    0
    Views:
    358
Loading...

Share This Page