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

后端 未结 8 1294
执笔经年
执笔经年 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 07:55

    last_insert_rowid() is part of the solution. It returns a row number, not the actual ID.

    cmd = CNN.CreateCommand();
    cmd.CommandText = "SELECT last_insert_rowid()";
    object i = cmd.ExecuteScalar();
    
    cmd.CommandText = "SELECT " + ID_Name + " FROM " + TableName + " WHERE rowid=" + i.ToString();
    i = cmd.ExecuteScalar();
    

提交回复
热议问题