Camadas
Camadas

Reputation: 509

C# With SQLite, real with comma on value how to get it?

on the SQLite have a table with several column with real, if the value of real as a dot on it ex 123.23 I can get this value without any problem with reader["columnname"].ToString();

But when the value of the column is as 123,23 if I try to get it it will come as 0

I did double check the value and its there but allways come as 0.

How I can read this properly?!

Edit:

Code where I'm reading the query

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);
        }
    }
}

Upvotes: 0

Views: 1092

Answers (1)

Lucifer
Lucifer

Reputation: 1594

If your datatype is double your code as given below. You can use SqliteDataReader.GetDouble(colIndex) to get the column index use SqliteDataReader.GetOrdinal(colname)

EG:

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

Upvotes: 1

Related Questions