OleDbDataAdapter.Update() 与 OleDbCommandBuilder
我正在使用 C# 和 OleDb 访问 Oracle 数据库,我已成功从查询中提取数据,但无法使用 OleDbAdapter.Update()
更新数据库,我的更新代码如下。 (“Adapter”是对用于成功从数据库中提取数据的 OleDbAdapter
对象的引用。)
OleDbCommandBuilder builder = new OleDbCommandBuilder(Adapter);
Adapter.UpdateCommand = builder.GetUpdateCommand();
Adapter.UpdateCommand.Prepare();
Adapter.Update(ds);
ds.AcceptChanges();
我当前收到“命令未准备好”。上面代码的第一行有错误。任何建议,我将不胜感激。
(编辑:ds 是数据集)
I am hitting an Oracle database using C# and OleDb, I have sucessfully pulled data from a query but I am unable to update the database using OleDbAdapter.Update()
, my update code is below. ("Adapter" is a reference to the OleDbAdapter
object used to sucessfully pull data out of the database.)
OleDbCommandBuilder builder = new OleDbCommandBuilder(Adapter);
Adapter.UpdateCommand = builder.GetUpdateCommand();
Adapter.UpdateCommand.Prepare();
Adapter.Update(ds);
ds.AcceptChanges();
I am currently getting a "Command was not prepared." error on the first line of the above code. Any suggestions and I would be very grateful.
(Edit: ds is the DataSet)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的版本不起作用,因为您查询存储过程。
如果您想一下:要工作它需要所有信息,例如密钥等。如果您在存储过程中连接表并仅选择没有一些重要主键的行子集,该怎么办?
在这些情况下,您可能需要编写/获取存储过程或自行查询并将其提供给适配器。
your version is not working because you query a stored procedure.
If you think of it: to work it needs all the information like keys and so on. What if you join tables in your stored procedure and select only a subset of rows without some important primary-keys?
In those cases you might need to write/get a stored procedure or query yourself and give it to the adapter.