【问题标题】:I have problem with the parameters in a query in dataset我对数据集中查询中的参数有疑问
【发布时间】:2019-11-11 19:09:42
【问题描述】:

我有一个 .NET 程序,其中包含一个访问/一个 sql 数据库的数据集。 我写了一个查询并使用了2个参数,但我得到了一个错误:

“@”附近的 WHERE 子句出错。 无法解析查询文本。

我的查询是:

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

【问题讨论】:

  • 如果你能分享minimal reproducible example,那就太棒了。我们需要了解您是如何运行该查询的。
  • 分享您的表结构,通常该错误意味着其中一个字段不正确(可能是拼写错误?)
  • 另一个错误文本:"missing operator) at the where..."

标签: c# sql .net ms-access dataset


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多