C# - InvalidCastException when fetching double from sqlite
- by Irro
I keep getting a InvalidCastException when I'm fetching any double from my SQLite database in C#. The exception says "Specified cast is not valid."
I am able to see the value in a SQL manager so I know it exists. It is possible to fetch Strings (VARCHARS) and ints from the database. I'm also able to fetch the value as an object but then I get "66.0" when it's suppose to be "66,8558604947586" (latitude coordination).
Any one who knows how to solve this?
My code:
using System.Data.SQLite;
...
SQLiteConnection conn = new SQLiteConnection(@"Data Source=C:\\database.sqlite; Version=3;");
conn.Open();
SQLiteDataReader reader = getReader(conn, "SELECT * FROM table");
//These are working
String name = reader.GetString(1);
Int32 value = reader.GetInt32(2);
//This is not working
Double latitude = reader.getDouble(3);
//This gives me wrong value
Object o = reader[3]; //or reader["latitude"] or reader.getValue(3)