sdr is my sqldatareader and I want to check that the curPrice value which is of type decimal is null.
inrec.curPrice = sdr.IsDBNull(7) ? (decimal?)null : sdr.GetDecimal(7);
This is the error message I am getting:
Cannot implicitly convert type 'decimal?' to 'decimal'. An explicit conversion exists (are you missing a cast?)
Where am I going wrong, please someone tell me.
inrec.curPrice = sdr.GetValueOrDefault(0m)
Since the left side (Price
) does not allow for null
then you cannot set its value to something that could be null
. Therefore, use .GetValueOrDefault(decimal defaultValue)
to return a default value when null
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With