自定义编写OleDbCommand命令
我有(另一个)关于编写 OleDbCommand 的问题。 我有一个复杂的选择命令(包括几个左连接),OleDbCommandBuilder 无法为我生成更新命令。
我似乎无法掌握编写更新命令背后的魔力。 我知道 SQL 更新语句的结构,但是我对它如何与 OleDbDataAdapter 一起工作有点困惑。 我知道当我调用adapter.Update()时,它只会更新DataTable的必要行,但是我不知道如何编写Update命令,以便它能够知道哪个表中的哪个字段 需要更新。
如果有人可以向我解释这个过程并为我指明正确的方向,我将非常感激。
编辑:由于没有人回答,我将发布有关我的问题的更多详细信息:
我有一个这种形式的选择语句:
select field1, field2, fieldn from table1 left join table2 on condition left join table3 on condition where condition1 and condition2
令我困惑的是我应该如何编写更新语句,因为我不能像这样写:
update table1, table2 set field1 = newvalue where condition1 and condition2
所以我不明白如何做到这一点,因为更新语句只接受一个表参数。 是否可以在这种 DataTables 上调用 OleDbDataAdapter.Update 方法?
I have (another) question about writing OleDbCommand's. I have a complex select command (includes several left joins) and OleDbCommandBuilder is unable to generate update commands for me.
I can't seem to grasp the magic behind writing update commands. I know the structure of the SQL update statement, however I am a bit puzzled about how this works with OleDbDataAdapter. I know that when I call adapter.Update() it will update only the necessary rows of DataTable, however I don't know how to write a Update command so it will be able to know what field in what table needs updating.
I would really appreciate if someone could explain the process to me and point me in the right direction.
Edit: Since no one is answering, I will post some more details regarding my question:
I have a select statement in this form:
select field1, field2, fieldn from table1 left join table2 on condition left join table3 on condition where condition1 and condition2
one is puzzling me is how should I write an update statement since I can not write it like this:
update table1, table2 set field1 = newvalue where condition1 and condition2
So I don't understand how to do this, since update statement only accepts one table argument. Is it even possible to call OleDbDataAdapter.Update method on this kind of DataTables?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你正在尝试这样做吗?
我很确定你不能一次更新多个表。 因此,您必须为每个表发出一个更新语句。
如果您试图减少到服务器的往返次数,您可以用“;”分隔语句,或者只需调用一个执行 n 次更新的存储过程
仍然查看 代替触发器,这可能是您正在寻找的
Are you trying to do this ?
I'm quite sure you can't update more than one table at a time. So you would have to issue one update statement for each of the tables.
If you're trying to reduce the number of roundtrips to the server you may separate the statements with ";", or juste call a stored procedure that would do the n updates
Still check out INSTEAD OF triggers, that maybe what you're looking for