簡體   English   中英

我在數據集中的查詢中的參數有問題

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM