C# 用C语言读取SQL Server数据库中的“real”数据类型
我有一种从SQL Server Compact db中提取数据的方法:C# 用C语言读取SQL Server数据库中的“real”数据类型,c#,.net,sql-server-ce,C#,.net,Sql Server Ce,我有一种从SQL Server Compact db中提取数据的方法: // Open the same connection with the same connection string. using (SqlCeConnection con = new SqlCeConnection(DatabaseControl.conString)) { con.Open(); // Read specific values in the table. using (SqlCeCom
// Open the same connection with the same connection string.
using (SqlCeConnection con = new SqlCeConnection(DatabaseControl.conString))
{
con.Open();
// Read specific values in the table.
using (SqlCeCommand com = new SqlCeCommand("SELECT Result FROM CpuResults WHERE Date = @date", con))
{
List<float> results = new List<float>();
com.Parameters.AddWithValue("date", Form1.date);
SqlCeDataReader reader = com.ExecuteReader();
while (reader.Read())
{
float resultsoutput = reader.GetInt32(0);
results.Add(resultsoutput);
}
cpuResults的结果列中的结果类型定义为Real。我正在尝试将此数据转换为浮点格式,因为结果列中的数据为0.02和1.23等,尽管当我运行我的方法时,我得到:
指定的强制转换无效
如果将列结果的数据类型更改为int,则不会出现问题。此行:
float resultsoutput = reader.GetInt32(0);
您正在尝试获取一个整数并将该值放入浮点
或者先获得一个浮点值:
float resultsoutput = reader.GetFloat(0);
或更改变量的类型:
int resultsoutput = reader.GetInt32(0);
这一行:
float resultsoutput = reader.GetInt32(0);
您正在尝试获取一个整数并将该值放入浮点
或者先获得一个浮点值:
float resultsoutput = reader.GetFloat(0);
或更改变量的类型:
int resultsoutput = reader.GetInt32(0);
这就是你的演员阵容失败的地方吗
float resultsoutput = reader.GetInt32(0);
试试这个:
float resultsoutput = reader.GetFloat(0);
这就是你的演员阵容失败的地方吗
float resultsoutput = reader.GetInt32(0);
试试这个:
float resultsoutput = reader.GetFloat(0);
为什么不试试reader.GetFloat0?为什么不试试reader.GetFloat0