bombai
bombai

Reputation: 967

Insert Null Value or decimal

If we are working with boolean and SQL bit, you can specify like this to insert on SQL table..

oHotel.active ? 1 : 0

I have a similar case, but I have to check a decimal value where it will

decimal.MaxValue

When i have to insert a null if it is not maxValue i have to insert his value..

supplement.amount == decimal.MaxValue ? DBNull.Value : supplement.amount

but don't work, it tell me that can't convert a null value into a decimal..

Someone knows a short working way like this? The value can be null in sql table..

Upvotes: 0

Views: 10430

Answers (2)

Suraj Singh
Suraj Singh

Reputation: 4069

Either the type of first_expression and second_expression must be the same, or an implicit conversion must exist from one type to the other..MSDN

I don't think you can use DBNULL directly as your first expression .

      decimal? nullval = null;  
       or
      decimal? nullval = Convert.ToDecimal(DBNull.Value);
      supplement.amount == decimal.MaxValue ? nullval : supplement.amount

Upvotes: 4

juergen d
juergen d

Reputation: 204854

use nullable decimals

decimal? oHotel = null;

Upvotes: 0

Related Questions