本文介绍了我需要正确的内连接条件查询构建,以便删除两个表中的记录:请帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试删除InvoiceItems和TAXINVOICE表中的记录。但是在写入Ole db语句时发生了一些查询分心。我正在尝试这样.MS访问中的确切表是InvoiceItems和TAXINVOICE。 InvoiceItems具有以下字段:InvoiceItem,InvoiceNumber,ProductId,Quantity,UOM,UnitPrice,GrossAmount,VAT,VatAmount,

总计

和TAXINVOICE有INVOICENO,MOBILENUMBER字段,CUSTOMERNAME,ADDRESS1,ADDRESS2,TINNO,PONO,TRANSPORT,BILLDATE,

InvoiceType,PODATE,totalGrossAmt,totalVatAmt,BILLAMT,TRANSPORTAMT,OTHERAMT,FINALAMT,

ROUNDOFF和GRANDTOTAL



我尝试了什么:



cmd = new OleDbCommand( DELETE InvoiceNumber,TAXINVOICE FROM InvoiceItems INNER JOIN TAXINVOICE WHERE InvoiceItems.InvoiceNumber = TAXINVOICE.INVOICENO和InvoiceNumber =+ txtInvoice.ToString(),conn);

I am trying to delete the records in InvoiceItems and TAXINVOICE tables.But there is some query distraction occuring while writing to Ole db statement.I am trying like this.The exact tables in MS access are InvoiceItems and TAXINVOICE. The InvoiceItems has the following fields as InvoiceItem,InvoiceNumber,ProductId,Quantity,UOM,UnitPrice,GrossAmount,VAT,VatAmount,
Total
and TAXINVOICE has fields of INVOICENO,MOBILENUMBER,CUSTOMERNAME,ADDRESS1,ADDRESS2,TINNO,PONO,TRANSPORT,BILLDATE,
InvoiceType,PODATE,totalGrossAmt,totalVatAmt,BILLAMT,TRANSPORTAMT,OTHERAMT,FINALAMT,
ROUNDOFF and GRANDTOTAL

What I have tried:

cmd = new OleDbCommand("DELETE InvoiceNumber,TAXINVOICE FROM InvoiceItems INNER JOIN TAXINVOICE WHERE InvoiceItems.InvoiceNumber=TAXINVOICE.INVOICENO and InvoiceNumber=" + txtInvoice.ToString() , conn);

推荐答案


"DELETE FROM InvoiceItems 
WHERE InvoiceNumber=TAXINVOICE.INVOICENO 
and InvoiceNumber=" + txtInvoice.ToString() 

"DELETE FROM TaxInvoice
WHERE InvoiceNo=" + txtInvoice.ToString()



但是,为了安全起见从SQL注入你真的应该使用 []。换句话说


However, in order to be safe from SQL injections you really should use OleDbParameter Class (System.Data.OleDb)[^]. In other words

"DELETE FROM InvoiceItems 
WHERE InvoiceNumber=TAXINVOICE.INVOICENO 
and InvoiceNumber=?"

"DELETE FROM TaxInvoice
WHERE InvoiceNo=?"



如解决方案1中所述,最简单的方法是定义外键并让数据库处理子行。请查看 []


这篇关于我需要正确的内连接条件查询构建,以便删除两个表中的记录:请帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 23:55