Getting the Last Insert ID with SQLite.NET in C#

后端 未结 8 1292
执笔经年
执笔经年 2020-11-30 07:20

I have a simple problem with a not so simple solution... I am currently inserting some data into a database like this:

kompenzacijeDataSet.KompenzacijeRow kom         


        
8条回答
  •  抹茶落季
    2020-11-30 08:10

    select last_insert_rowid();
    

    And you will need to execute it as a scalar query.

    string sql = @"select last_insert_rowid()";
    long lastId = (long)command.ExecuteScalar(sql); // Need to type-cast since `ExecuteScalar` returns an object.
    

提交回复
热议问题