I want to save a double into my SQLite DB with C# and read it out again.
Now the problem:
At first the input:
If i save a double with a point ( e.g 20.50
) an insert it in my database i get 2050.0
.
If i save it with a comma ( e.g 20,30
) i get in my db 20,3
. That what i want.
Code Input:
String sql = $"INSERT INTO tablename (number) VALUES ('{number}')";
SQLiteConnection dbConnection = new SQLiteConnection("Data Source = " + nameDB + ".sqlite; Version = 3;");
dbConnection.Open();
SQLiteCommand Command = new SQLiteCommand(sql, dbConnection);
Command.ExecuteNonQuery();
Command.Parameters.Clear();
dbConnection.Close();
number is a double in c# and in sqllite REAL
But now the output:
If in my db is the value 20,3 and i read it out with:
double number = reader.GetDouble(reader.GetOrdinal("tablename"));
Error: InvalidCastException: Specified cast is not valid.
or
decimal number = reader.GetDecimal(reader.GetOrdinal("tablename"));
Error: wrong inputformat
If i use the reader without the get-methods i get the number without decimals after the comma like int.
Both works if the format in the db is with a point instead of a comma. But this doesnt work for the input.
Is there a solution for this problem?