简体   繁体   中英

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. I wrote a query and used 2 parameters, but I got an error:

Error in WHERE clause near '@'. 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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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