如何在sqlite xamarin表单中获取最后插入的id

时间:2016-10-14 07:02:53

标签: sqlite xamarin.forms

我想获得我的查询的最后插入ID

public IEnumerable<DraftOrderInfoTable> SaveDraftOrderInfo(int orderno, int customerid, string customername, string customeremail, string orderdate)
    {
        var draftorderinfo = new DraftOrderInfoTable
        {
            OrderNo = orderno,
            CustomerId = customerid,
            CustomerName = customername,
            CustomerEmail = customeremail,
            OrderDate = orderdate,
        };

        _connection.Insert(draftorderinfo);
    }

请告诉我如何获取最后插入的ID?

1 个答案:

答案 0 :(得分:0)

在插入查询之后,只需使用SQLite last_insert_rowid()函数来获取刚刚生成的SQLite自动增量字段的值:

select last_insert_rowid();