Forum Xamarin Cross Platform with Xamarin


Good day i seem to be having issues reading a float datatype from the local sqlite db. I can write the values in correctly, (viewed the database file) but for some reason i cannot read the value.

while (r.Read())

float lon = (float)r["lon"];

This method throws
System.InvalidCastException: Cannot cast from source type to destination type.

Any help would be greatly appreciated


  • prashantvcprashantvc USXamarin Team Xamurai


    Could you post your table definition? It's possible that "lon" may not be of type float!

    Otherwise just try getting value for "lon" and check what type the value is.
    Something like:

    object lon = r["lon"];

  • Hi Prashant thank you for the reply below is my table definition, the strange thing is that it works when i use .

    double lon = (double)r["lon"];

    public static readonly string create_incident = "CREATE TABLE [incident] ([_id] INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE, [type] TEXT NOT NULL, [gps_date] DATETIME, [lat] float, [lon] float, status TEXT NOT NULL)";

Sign In or Register to comment.