Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 用C语言读取SQL Server数据库中的“real”数据类型_C#_.net_Sql Server Ce - Fatal编程技术网

C# 用C语言读取SQL Server数据库中的“real”数据类型

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

我有一种从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 (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