Dapper.net, Specified cast is not valid. cannot use type float

dapper sql-server-2008

Question

I have a table,there's a field called "water", the data type for this field in sql server 2008 is float.

in my code, I also use float.

 public float? Water { get; set; }

here's the error message I got.

{"Specified cast is not valid."}
{"Error parsing column 2 (Water=15.87 - Double)"}

if I changed the type to double , everything works.

 public double? Water { get; set; }

I went back to the Database, all values for water field are between 0-100. there are a few nulls.

please explain to me why I have to use double instead of float?

Accepted Answer

This has nothing to do with Dapper. If you check the SqlDbType conversion site, you'll notice that a float in SQL Server is a double in .NET

http://msdn.microsoft.com/en-us/library/system.data.sqldbtype.aspx#Mtps_DropDownFilterText




Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why