在我的项目中,我使用System.Data.SQLite。数据库有表Tags
,其中包含自动增量主字段ID
(类型Integer
)。当我写:如何在SQLite插入查询中返回自动增量值?
using (SQLiteCommand command = conn.CreateCommand())
{
command.CommandText = "insert into Tags(name) values(@name) returning into @id";
command.Parameters.Add("@id", DbType.Int32).Direction = ParameterDirection.Output;
command.ExecuteNonQuery();
}
Visual Studio说,该操作不支持。如何解决它?发生在行
错误:
command.Parameters.Add("@id", DbType.Int32).Direction = ParameterDirection.Output;
在哪里工作代码?我有同样的问题,但我发现“SELECT last_insert_rowid()”令人讨厌地模糊。 @name如何设置? “SELECT last_insert_rowid()”去哪里?除此之外:您为Calibre添加了哪些功能? ;) – hoytster 2012-02-17 23:52:22
我想,你不能设置@name。你的钥匙必须有名字'Id'。 “SELECT last_insert_rowid()”使用最后一个插入。 – dublicator 2012-02-22 08:16:12