get autoincrement field for just added row


This from manual:

[code]Dim row As New DatabaseRecord
// ID will be updated automatically
row.Column(“Name”) = “Penguins”
row.Column(“Coach”) = “Bob Roberts”
row.Column(“City”) = “Boston”

App.DB.InsertRecord(“Team”, row)

How do I get that ID if it’s auto_increment in database and all other colums are not unique?

If it’s a MySQL database you can run this command


It will return the last inserted auto increment id.

If you use SQLite database, then it will be automatically create an autoincrement row for you. the row has the name “rowid”. See "Language Reference - SQLiteDatabase.

Or try


For now it is MySQL but finally it will be on MSSQL. Does this “SELECT LAST_INSERT_ID();” work in MSSQL?

Haven’t tried but this should work on MSSQL.


Take a look at attached link

I’d look to use the output clause, think that’s the preferred method in newer versions of MSSQL…

From the MySQL section of the User Guide:

Dim lastValue As Integer? lastValue = db.GetInsertID