Why is a SQL float different from a C# float


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?

10/9/2009 10:14:00 PM

Accepted Answer

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

9/23/2008 5:41:20 PM

A float in SQL is a Double in the CLR (C#/VB). There's a table of SQL data types with the CLR equivalents on MSDN.

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow