Reputation: 404
i have an issue by getting last_insert_rowid in my sqlite db in c#. Here is what i have, the insert with my dynamic params works well for my project and i like to keep this methode constant:
using (IDbConnection cnn = new SQLiteConnection(LoadConnectionString()))
{
int erg = cnn.Execute("insert into tblPerson (Vorname, Nachname, Ort) values(@Vorname, @Nachname, @Ort);", tblPerson);
}
That works fine, but this method don't allow me to access the last inserted id. But i need this: cnn.last_insert_rowid()
.
IDbConnection have no definition for last_insert_rowid or something like that. And a select last_insert_rowid( ), give an error: "no definition for cnn.last_insert_rowid()"
Do someone have a idea, please no workarounds like select * from tblPerson ORDER BY tblPerson DESC
I realy need the confirmed last inserted id (idPerson).
idPerson is my Primary-Key and is Autoincrement.
Upvotes: 0
Views: 474
Reputation: 416159
Add select last_insert_rowid();
to the end of the sql string, and update the calling code to use Query()
instead of Execute()
so you can check the result of the additional select statement.
Upvotes: 1