SQLite with WP8 is driving me crazy .:(
All I want to do is get the value of the last inserted id ...
I have:
class ShoppingItem { [SQLite.PrimaryKey, SQLite.AutoIncrement] public int Id {get; set;} public string Name {get; set;} public string Shop {get; set;} public bool isActive {get; set;} }
Well, neither the SQLiteConnection object used nor its Table<ShoppingItem> seems to contain the corresponding member that contains the last identifier.
So, I tried:
private int GetLastInsertedRowID() { int Result = -1; using (var db = new SQLiteConnection(m_DatabasePath)) { Result = db.ExecuteScalar<int>("SELECT last_insert_rowid();"); } return Result; }
But this function always returns 0 :( But when I read all the ShoppingItem records, their identifiers have values! = 0.
So my question is: how can I recover the last inserted id?
PS: changing the SQL query to SELECT last_insert_rowid() FROM ShoppingItem; gave the same result.
PPS: solutions like Getting the last insert identifier with SQLite.NET in C # do not compile, apparently an earlier version of SQLite is used with a completely different API
source share