我有一個從SQL Server精簡分貝拉低數據的方法:讀「真正」的數據,在C#中的SQL Server數據庫類型
// 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
。由於Result
列中的數據例如是數據,因此我試圖將此數據轉換爲浮點格式。 0.02和1.23等。雖然當我運行我的方法時,我得到:
指定的轉換無效。
如果我改變Result
列的數據類型爲int,問題不會發生..