简体   繁体   English

我在数据集中的查询中的参数有问题

[英]I have problem with the parameters in a query in dataset

I have a .NET program with a dataset to an access/a sql DB. 我有一个.NET程序,带有一个访问/ sql DB的数据集。 I wrote a query and used 2 parameters, but I got an error: 我编写了一个查询并使用了2个参数,但出现错误:

Error in WHERE clause near '@'. “ @”附近的WHERE子句中的错误。 Unable to parse query text. 无法解析查询文本。

My query is: 我的查询是:

SELECT DocID, DocCustomerNumber, 
    DocSessionID, DocTitle, DocKlaser, DocBarcodes
FROM VTblASMCustomersDocsAndGroupCodes
WHERE DocCustomerNumber = @cusNum AND 
    DocSessionID = @asmNum

Microsoft Access doesn't use named parameters. Microsoft Access不使用命名参数。 It uses positional parameters. 它使用位置参数。 So the order of the parameters is important when you set the values of the parameters. 因此,在设置参数值时,参数的顺序很重要。

Change your query to this: 将查询更改为此:

SELECT DocID, DocCustomerNumber, 
    DocSessionID, DocTitle, DocKlaser, DocBarcodes
FROM VTblASMCustomersDocsAndGroupCodes
WHERE DocCustomerNumber = ? AND 
    DocSessionID = ?

Then use this code to pass the parameters: 然后使用此代码传递参数:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM