Click here to Skip to main content
15,887,776 members
Please Sign up or sign in to vote.
2.33/5 (2 votes)
See more:
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);
Posted
Updated 16-Oct-16 19:56pm

1 solution

You can't update two tables with a single UPDATE statement, if you are trying to do something like so. But you can use JOINS 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-
C#
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);


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.
:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900