【问题标题】:How to retrieve inserted id after inserting row in SQLite using C#? [duplicate]使用 C# 在 SQLite 中插入行后如何检索插入的 id? [复制]
【发布时间】:2018-08-29 23:17:57
【问题描述】:

我问的是 C# 等效的 of this question。当我插入一行具有自增主键的数据时,我该如何读回主键?

我需要这个用于 SQlite (this answers for SQL Server)。

谢谢 - 戴夫

【问题讨论】:

  • 您使用的是哪个 sqlite3 绑定?
  • 我们使用的是 SQlite ADO.NET 连接器。 System.Data.SQLite 版本 1.0.108.0

标签: .net sqlite


【解决方案1】:
// IDbCommand cmd
cmd.ExecuteScalar();
return ((SQLiteConnection) cmd.Connection).LastInsertRowId;

非常简单:)

【讨论】:

    猜你喜欢
    • 2011-09-08
    • 1970-01-01
    • 2018-08-07
    • 1970-01-01
    • 2015-09-30
    • 1970-01-01
    • 2014-08-08
    • 1970-01-01
    • 2011-03-28
    相关资源
    最近更新 更多