could not be set to a 'System.Decimal' value. You must set this property to a non-null value of type 'System.Double' could not be set to a 'System.Decimal' value. You must set this property to a non-null value of type 'System.Double' sql-server sql-server

could not be set to a 'System.Decimal' value. You must set this property to a non-null value of type 'System.Double'


I think it might be because of null value conversion attempt to be stored in double.

Change your double to

double?

For explanation, please see the link below:http://msdn.microsoft.com/en-us/library/2cf62fcy.aspx

Thanks!


It may be the problem from DB ,from my experience I got this exception because I use data from store-procedure (generate object class using entity framework)

that one number field in my SP I supplying a data contract like this

CAST(NULL AS DECIMAL) AS UnitAmount

so in my code(after entity framework generate class) I got class that contain

Decimal UnitAmount{get;set;}

but when I run my code this error happen

...could not be set to a 'System.Int32' value. You must set this property to a non-null value of type 'System.Decimal'.

it's because in my SP there is one case condition that I return my result like this so the data type return is mismatch.

-- if no dataSelect ... ,       0  as UnitAmount,        ....

If you don't cast/convert the result 0 ->it will be seen as Int32 (0.00-> seen as Decimal ,)


Use

public decimal number { get; set; } 

or

public double number { get; set; }

link