为什么SQL Anywhere会忽略@name参数?

问题描述 投票:3回答:2

我正在使用Dapper查询SQL Anywhere数据源,并且我收到一个错误,使得看起来我的where子句值的“@”前缀被忽略。

 Double balance = qb.Query<Double>("select end_balance_amt from QBReportAdminGroup.v_lst_customer where list_ident = @listid", new { listid = ListID }).Single();

错误:

Column '@listid' not found

我可以访问该表,我的手动查询工作正常。

select end_balance_amt from QBReportAdminGroup.v_lst_customer where list_ident = '8000000B-1433635931'

例:

.net ado.net dapper sqlanywhere
2个回答
1
投票

对于SQL Anywhere及其.Net数据提供程序(至少为Sap.Data.SQLAnywherev4.5),参数应以:为前缀,而不是@

在我看来,这就是问题所在。但我不知道Dapper是否应该从其用户那里抽象出这种供应商的特定行为。

所以你应该尝试:

Double balance = qb.Query<Double>(
    "select end_balance_amt from QBReportAdminGroup.v_lst_customer where list_ident = :listid",
    new { listid = ListID }).Single();

1
投票

找我试图使用未声明的变量@listid。

如果我在DB Anywhere中使用DBISQL,我会写这样的东西:

开始

DECLARE @list varchar(20);

SET @list ='8000000B-1433635931';

从QBReportAdminGroup.v_lst_customer中选择end_balance_amt,其中list_ident = @listid“;

结束

© www.soinside.com 2019 - 2024. All rights reserved.