checking for a null value in a data reader

Discussion in 'ASP .Net' started by ]-[aTc]-[, Dec 2, 2003.

  1. ]-[aTc]-[

    ]-[aTc]-[ Guest

    Hello
    I have the following code...
    string chkString = " " + dr.GetString(37) + " ";

    and I get an error message of ...

    Data is Null. This method or property cannot be called on Null values.

    How do i check for this null value.

    I've tried many things like this..

    if (dr.GetValue(37) != null)

    { code}

    but does not work

    Please help

    Thank you

    --Mike
     
    ]-[aTc]-[, Dec 2, 2003
    #1
    1. Advertising

  2. Try

    if (!dr.IsDbNull(37))
    ...

    And don't feel bad. It took me a couple of hours to find
    this the first time I went looking. ;)

    Bruce Johnson
    http://www.ObjectSharp.com/Bruce

    >-----Original Message-----
    >Hello
    >I have the following code...
    >string chkString = " " + dr.GetString(37) + " ";
    >
    >and I get an error message of ...
    >
    >Data is Null. This method or property cannot be called

    on Null values.
    >
    >How do i check for this null value.
    >
    >I've tried many things like this..
    >
    >if (dr.GetValue(37) != null)
    >
    >{ code}
    >
    >but does not work
    >
    >Please help
    >
    >Thank you
    >
    > --Mike
    >
    >
    >.
    >
     
    Bruce Johnson, Dec 2, 2003
    #2
    1. Advertising

  3. ]-[aTc]-[

    vijay1584

    Joined:
    Aug 24, 2006
    Messages:
    3
    Error

    Respected Sir ,

    i have suffer from this error : Data is Null. This method or property cannot be called on Null values.

    // Error in code
    dr.GetString(20) // Error line


    In database GetString(20) is not specified Please reply me

    E-mail


    Regards ,

    vijay
     
    vijay1584, Aug 24, 2006
    #3
  4. ]-[aTc]-[

    vijay1584

    Joined:
    Aug 24, 2006
    Messages:
    3
    About Error

    Respected Sir ,

    i have suffer from this error : Data is Null. This method or property cannot be called on Null values.

    // Error in code
    dr.GetString(20) // Error line


    In database GetString(20) is not specified Please reply me

    E-mail


    Regards ,
    vijay
     
    vijay1584, Aug 24, 2006
    #4
  5. ]-[aTc]-[

    vijay1584

    Joined:
    Aug 24, 2006
    Messages:
    3
    Respected Sir ,

    i have suffer from this error : Data is Null. This method or property cannot be called on Null values.

    // Error in code
    dr.GetString(20) // Error line


    In database GetString(20) is not specified Please reply me

    E-mail


    Regards ,
     
    vijay1584, Aug 24, 2006
    #5
  6. ]-[aTc]-[

    chris.seater

    Joined:
    Oct 2, 2009
    Messages:
    1
    Thanks for the post, I had been trying to solve the problem all day.
     
    chris.seater, Oct 2, 2009
    #6
  7. ]-[aTc]-[

    shebmanchester

    Joined:
    Nov 28, 2011
    Messages:
    1
    thanks

    :congrats:saved my life Bruce Johnson. thanks... been looking for this snippet...
     
    shebmanchester, Nov 28, 2011
    #7
    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. excelleinc.com
    Replies:
    1
    Views:
    1,419
    Hermit Dave
    Sep 10, 2004
  2. Replies:
    5
    Views:
    26,710
    Mike Schilling
    Mar 29, 2006
  3. Guilherme Grillo

    reader inside a reader

    Guilherme Grillo, Nov 7, 2007, in forum: ASP .Net
    Replies:
    5
    Views:
    528
    sloan
    Nov 7, 2007
  4. jason
    Replies:
    13
    Views:
    883
    John B. Matthews
    May 14, 2010
  5. Pokkai Dokkai
    Replies:
    1
    Views:
    237
    Hassan Schroeder
    Mar 24, 2008
Loading...

Share This Page