Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 自定义写入OleDbCommand命令_C#_Sql_Oledb_Oledbcommand - Fatal编程技术网

C# 自定义写入OleDbCommand命令

C# 自定义写入OleDbCommand命令,c#,sql,oledb,oledbcommand,C#,Sql,Oledb,Oledbcommand,我还有一个关于写OleDbCommand的问题。我有一个复杂的select命令(包括几个左连接),OleDbCommandBuilder无法为我生成更新命令 我似乎无法理解编写更新命令背后的魔力。我知道SQL update语句的结构,但是我对OleDbDataAdapter的工作原理有点困惑。我知道,当我调用adapter.Update()时,它将只更新DataTable中必要的行,但是我不知道如何编写更新命令,以便它能够知道哪些表中的哪些字段需要更新 如果有人能向我解释这个过程,并为我指出正确

我还有一个关于写OleDbCommand的问题。我有一个复杂的select命令(包括几个左连接),OleDbCommandBuilder无法为我生成更新命令

我似乎无法理解编写更新命令背后的魔力。我知道SQL update语句的结构,但是我对OleDbDataAdapter的工作原理有点困惑。我知道,当我调用adapter.Update()时,它将只更新DataTable中必要的行,但是我不知道如何编写更新命令,以便它能够知道哪些表中的哪些字段需要更新

如果有人能向我解释这个过程,并为我指出正确的方向,我将不胜感激

编辑:由于没有人回答,我将发布有关我的问题的更多详细信息:

我在此表单中有一个select语句:

select field1, field2, fieldn from table1 left join table2 on condition left join table3 on condition where condition1 and condition2
一个让我困惑的问题是,既然我不能这样写,我应该如何写update语句:

update table1, table2 set field1 = newvalue where condition1 and condition2

所以我不明白怎么做,因为update语句只接受一个表参数。甚至可以对此类数据表调用OleDbDataAdapter.Update方法吗?

您正在尝试这样做吗

update table1 set table1.field1 = table2.field2
from table1 left join table2 on condition1
where condition2 and condition3
我很确定一次不能更新多个表。因此,您必须为每个表发出一条update语句。 如果您试图减少到服务器的往返次数,可以用“;”分隔语句,或者只需调用一个执行n次更新的存储过程


请继续查看,这可能是您正在寻找的

这肯定是有帮助的,但是仍然存在一个问题。DataRow包含来自不同表的列,其中任何一个都可以修改——我还不清楚如何编写一个更新命令来修改这些字段中的任何一个。我很确定,您必须为每个表发出一个update语句,然后…签出而不是触发器,这可能就是您要查找的