3

I am using Dapper to query a SQL Anywhere Datasource, and I am getting an error that makes it seem that the "@" prefix for my where clause value is ignored.

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

Error:

Column '@listid' not found

I have access to that table and my manual query works fine.

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

Example:

enter image description here

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Israel Lopez
  • 1,135
  • 3
  • 11
  • 25

2 Answers2

3

With SQL Anywhere and its .Net data provider (at least Sap.Data.SQLAnywherev4.5), parameters should be prefixed with : instead of @.

This looks to me as being the issue in your case. But I do not know if Dapper is supposed to abstract away such vendor's specific behavior from its users.

So you should try with:

Double balance = qb.Query<Double>(
    "select end_balance_amt from QBReportAdminGroup.v_lst_customer where list_ident = :listid",
    new { listid = ListID }).Single();
Frédéric
  • 9,364
  • 3
  • 62
  • 112
1

Looks for me that you try to use a variable @listid which is not declared.

If I use DBISQL with SQL Anywhere I would have wrote somthing like this:

BEGIN

DECLARE @list varchar(20);

SET @list = '8000000B-1433635931';

select end_balance_amt from QBReportAdminGroup.v_lst_customer where list_ident = @listid";

END