C#使用SQLite,真实的逗号值如何获取它?

时间:2018-05-30 09:24:54

标签: c# sqlite compact-framework

在SQLite上有一个表格,其中有几列是真实的,如果真实的值为真的点123.23我可以reader["columnname"].ToString();

获得此值而没有任何问题

但是当列的值为123,23时,如果我尝试获取它,它将为0

我确实仔细检查了它的值,但总是为0。

我如何正确阅读?!

编辑:

我正在阅读查询的代码

using (SQLiteCommand cmd = con.CreateCommand())
{
    cmd.CommandText = "SELECT * FROM Ajuda_Compras WHERE Cod_Art = @prodCod";
    cmd.Parameters.AddWithValue("@prodCod", value);
    using (SQLiteDataReader reader = cmd.ExecuteReader())
    {
        ManagerLastPrices tempLast;
        while (reader.Read())
        {
            tempLast = new ManagerLastPrices();
            tempLast.ProdCod = reader["Cod_art"].ToString();
            tempLast.Descr = reader["Descricao"].ToString();
            tempLast.Date = reader["Data"].ToString();
            tempLast.FiscalYear = reader["AnoFiscal"].ToString();
            tempLast.DocType = reader["TipoDoc"].ToString();
            tempLast.Serie = reader["Serie"].ToString();
            tempLast.DocNumber = reader["N_Doc"].ToString();
            tempLast.Qtd = reader["Qtd"].ToString();
            tempLast.DiscountPrice = reader["P_Compra"].ToString();
            tempLast.DiscountPerc = reader["Desc1"].ToString();
            tempLast.Price = reader["P_Unit"].ToString();
            tempLast.EntityID = reader["Id_Terceiro"].ToString();
            tempLast.Entity = reader["Terceiro"].ToString();
            this._listLastPrices.Add(tempLast);
        }
    }
}

1 个答案:

答案 0 :(得分:1)

  

如果您的数据类型是您的代码的两倍,如下所示。   您可以使用SqliteDataReader.GetDouble(colIndex)将列索引用于SqliteDataReader.GetOrdinal(colname)

EG:

double temp= reader.GetDouble(reader.GetOrdinal("P_Compra"));
tempLast.DiscountPrice = temp.ToString("#,#", CultureInfo.InvariantCulture);