如何将命令/SQL 语句添加到强类型 TableAdapter 的更新/插入命令?
请参阅此问题。我有以下使用强类型数据集针对 SQLite 数据库执行的代码。
messagesAdapter.Update(messages);//messages is a DataTable
var connection = messagesAdapter.Connection;
var retrieveIndexCommand= connection.CreateCommand();
retrieveIndexCommand.CommandText = @"Select last_insert_rowid()";
connection.Open();
var index = retrieveIndexCommand.ExecuteScalar();
connection.Close();
这不起作用,因为 last_inser_rowid() 始终返回零。这是因为需要在 TableAdapter 的 Update 命令使用的同一连接期间调用它。如何更改 TableAdapter 的插入或更新命令以使其返回索引?
See this question. I have the following code that executes against a SQLIte database using a strongly typed dataset.
messagesAdapter.Update(messages);//messages is a DataTable
var connection = messagesAdapter.Connection;
var retrieveIndexCommand= connection.CreateCommand();
retrieveIndexCommand.CommandText = @"Select last_insert_rowid()";
connection.Open();
var index = retrieveIndexCommand.ExecuteScalar();
connection.Close();
This does not work as the last_inser_rowid() always returns zero. This caused by the fact that it needs to be called during the same connection that is used by the TableAdapter's Update command. How can I change the the TableAdapter's Insert or Update command so that it return the index?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您要插入单行,您可以使用它:
您还可以使用它插入多行并将您的 id 分配给每一行:
注意:请务必打开/关闭您的连接
If you are inserting a single row, you can use this:
You can also use it to insert multiple rows and assign your id to each one:
Note: Be sure to open / close your connection