Results 1 to 4 of 4

Thread: empty datarowview cell

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2014
    Posts
    184

    empty datarowview cell

    ((DataRowView)kundenBindingSource.Current).Row.Field<double>(11)


    with this i can get the value of the 11. column but what if i wanted to check wheter the value is empty, how would i do that?

    i tried :
    if (((DataRowView)kundenBindingSource.Current).Row.Field<double>(11) == null ) it says a double type can never be null i also tried == DBNull.Value but it is underlined and does not compile. how to check if the cell is empty?

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: empty datarowview cell

    It doesn't make sense to call Field<double> there because the whole point of that method is to get a double value from the field, which is obviously impossible if it's null.

    As the documentation states, you can use nullable types with the Field<T> method, so you can use double? instead of double and then you can compare the result to null. Of course, you will then have to account in the subsequent for the fact that you have a double? rather than a double.

    Alternatively, you can call the IsNull method of the DataRow first and then only call Field<double> if it returns False.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2014
    Posts
    184

    Re: empty datarowview cell

    Thanks, i was a little bit confused. i just used == 0 it works too.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: empty datarowview cell

    Quote Originally Posted by moxid View Post
    Thanks, i was a little bit confused. i just used == 0 it works too.
    I'm surprised that that works but, even if it does, it means that you can't distinguish between an actual zero value and no value. Given that there are proper ways to deal with nulls, I'd suggest using one of those.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width