1
Vote

InvalidCastException - Issue with Double column type.

description

When creating a table with a double column (targeting MS Sql Express 2012)
  DBCreateTableQuery createTableQuery = DBQuery.Create.Table("dbo", "mytablename");
  createTableQuery = createTableQuery.Add("mydouble", DbType.Double, DBColumnFlags.Nullable);
  db.ExecuteNonQuery(createTableQuery);
This creates a column in the database with a column type of "real"

When you then read data from that column:-
var value = reader.GetDouble(i);
This throws an invalid cast exception - as the underlying value is actually a Single.

After checking Here it looks as though the correct column data type in Sql Server for a double is Float (53) rather than real.

comments