Search code examples
c#odbcsybasesap-iq

Error when trying to use ODBC Named Parameter with SAP IQ/Sybase IQ DB


I have the following command that works on mySQL but not working with SAP IQ/Sybase IQ DB:

string sql = "select * from someTable where fieldName=@name";
command.CommandText = sql;
command.Parameters.Add(new OdbcParameter()
{
    DbType = System.Data.DbType.Int32,
    Value = 1,
    ParameterName = "@name",
    Direction = System.Data.ParameterDirection.Input
});

command.ExecuteNonQuery();

the error is:

ERROR [42S22] [Sybase][ODBC Driver][Sybase IQ]Column '@name' not found

I suspect that named parameters aren't working with Sybase IQ.


Solution

  • The solution is to count on the order of the parameters and use question maek instead of the named parameter:

    string sql = "select * from someTable where fieldName=?";