[英]I have problem with the parameters in a query in dataset
我有一个.NET程序,带有一个访问/ sql DB的数据集。 我编写了一个查询并使用了2个参数,但出现错误:
“ @”附近的WHERE子句中的错误。 无法解析查询文本。
我的查询是:
SELECT DocID, DocCustomerNumber,
DocSessionID, DocTitle, DocKlaser, DocBarcodes
FROM VTblASMCustomersDocsAndGroupCodes
WHERE DocCustomerNumber = @cusNum AND
DocSessionID = @asmNum
Microsoft Access不使用命名参数。 它使用位置参数。 因此,在设置参数值时,参数的顺序很重要。
将查询更改为此:
SELECT DocID, DocCustomerNumber,
DocSessionID, DocTitle, DocKlaser, DocBarcodes
FROM VTblASMCustomersDocsAndGroupCodes
WHERE DocCustomerNumber = ? AND
DocSessionID = ?
然后使用此代码传递参数:
cmd.Parameters.AddWithValue("param1", param1); // param1 = value of DocCustomerNumber
cmd.Parameters.AddWithValue("param2", param2); // param2 = value of DocSessionID
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.