Why is a SQL float different from a C# float

Keith Sirmons picture Keith Sirmons · Sep 23, 2008 · Viewed 60.9k times · Source

Howdy, I have a DataRow pulled out of a DataTable from a DataSet. I am accessing a column that is defined in SQL as a float datatype. I am trying to assign that value to a local variable (c# float datatype) but am getting an InvalidCastExecption

DataRow exercise = _exerciseDataSet.Exercise.FindByExerciseID(65);
_AccelLimit = (float)exercise["DefaultAccelLimit"];  

Now, playing around with this I did make it work but it did not make any sense and it didn't feel right.

_AccelLimit = (float)(double)exercise["DefaultAccelLimit"];

Can anyone explain what I am missing here?

Answer

Austin Salonen picture Austin Salonen · Sep 23, 2008

A SQL float is a double according to the documentation for SQLDbType.