-
Apr 21st, 2018, 05:46 AM
#1
Thread Starter
Addicted Member
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?
-
Apr 21st, 2018, 06:27 AM
#2
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.
-
Apr 21st, 2018, 07:27 AM
#3
Thread Starter
Addicted Member
Re: empty datarowview cell
Thanks, i was a little bit confused. i just used == 0 it works too.
-
Apr 21st, 2018, 08:07 AM
#4
Re: empty datarowview cell
Originally Posted by moxid
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|