如何在用于update语句的查询中加入内部联接语句? [英] How can I join the inner join statement in a query that is used for update statement?
问题描述
我需要加入两个表结果并在Inner join语句的帮助下更新两个表的属性
我尝试过:
cmd = new OleDbCommand(UPDATE InvoiceItems set Description ='+ txtProductName +',Quantity ='+ txtQty.Text +', UOM ='+ txtUOM.Text +',UnitPrice ='+ txtUnitPrice.Text +',GrossAmount ='+ txtGrossAmount.Text +',VAT ='+ txtVAT.Text +',VatAmount = '+ txtVatAmount.Text +',Total ='+ txtTotal.Text +',INNER JOIN InvoiceItems,TAXINVOICE on InvoiceItems.InvoiceNumber = TAXINVOICE.InvoiceNumber其中InvoiceItems.InvoiceNumber =+ txtInvoice.Text.Trim()+ ,conn);
I need to join the two table results and update the attributes of two tables with the help of Inner join statement
What I have tried:
cmd = new OleDbCommand("UPDATE InvoiceItems set Description ='" + txtProductName + "',Quantity = '" + txtQty.Text + "',UOM = '" + txtUOM.Text + "',UnitPrice ='" + txtUnitPrice.Text + "',GrossAmount ='" + txtGrossAmount.Text + "',VAT = '" + txtVAT.Text + "',VatAmount ='" + txtVatAmount.Text + "',Total ='" + txtTotal.Text + "', INNER JOIN InvoiceItems,TAXINVOICE on InvoiceItems.InvoiceNumber=TAXINVOICE.InvoiceNumber where InvoiceItems.InvoiceNumber= " +txtInvoice.Text.Trim()+ "",conn);
推荐答案
如果使用单个UPDATE
语句更新两个表,你正试图做这样的事情。但是你可以使用JOINS
来获取更新到一个表的数据,并且可以用于装配等。
对查询进行更正应如下所示 -
You can't update two tables with a singleUPDATE
statement, if you are trying to do something like so. But you can useJOINS
to get the data for updation to one table and can be used for fiter etc.
Doing corrections to your query should look like following-
cmd = new OleDbCommand("UPDATE Inv set Description ='" + txtProductName + "',Quantity = '" + txtQty.Text + "',UOM = '" + txtUOM.Text + "',UnitPrice ='" + txtUnitPrice.Text + "',GrossAmount ='" + txtGrossAmount.Text + "',VAT = '" + txtVAT.Text + "',VatAmount ='" + txtVatAmount.Text + "',Total ='" + txtTotal.Text + "' FROM InvoiceItems Inv INNER JOIN TAXINVOICE TInv on Inv.InvoiceNumber=TInv.InvoiceNumber where Inv.InvoiceNumber=" +txtInvoice.Text.Trim(),conn);
注意:正如我已经说过的, UPDATE
声明您想要更新的声明应该只来自 UPDATE table_name
中提到的表格(例如,在您的情况下为InvoiceItems)。
如果您正在尝试实现其他目标,请告诉我。
:)
Note: As I already said, all the columns in your UPDATE
statement those you want to update should be from the table mentione in UPDATE table_name
only(i.e, InvoiceItems in your case).
Please let me know, if you are trying achieve something else.
:)
这篇关于如何在用于update语句的查询中加入内部联接语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!