C#读取SQL Server字段报错:System.InvalidCastException:“Specified cast is not valid.”
reader.GetDouble(reader.GetOrdinal("so2t"));
数据库设计:
表中的数据类型是real,代码中用getDouble无法读取。
网上查询找到了答案:
SQL Server的real类型在C#中对应单精度Single, 用常用的float即可。
reader.GetFloat(reader.GetOrdinal("so2t"));
问题解决。