Page 1 of 1

getting autoinc value

Posted: Fri 18 Feb 2011 13:08
by eugenem
Is there any reasonable way to automatically get autoinc values after inserting into table?

ds2.Groups.AddGroupsRow(...);
ds2.Groups.Update();

this reloads table completely and gets new ids obviously, but it doesn't feel good
ds2.Groups.Clear();
ds2.Groups.Fill();

there is autoinc ID field in the table

Posted: Mon 21 Feb 2011 18:14
by Shalex
You are right, the mentioned code doesn't look good. But SQLite engine doesn't support SQL for updating result set with the values generated in the database for the autoincrement columns. So, your code can be solution.

The SQLiteCommand class includes the InsertID property which returns the rowid of the most recent successful INSERT into the database. This is just for information (it doesn't help in this situation).