且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

ODBC SQL,在where子句中使用保留字

更新时间:2023-02-04 23:40:37

参数化您希望用作WHERE子句一部分的字符串,并且在使用关键字'PRIORITY'时遇到相同的问题.修改C#代码以使用参数后,它就起作用了.

Parameterise the string you wish to use as part of the WHERE clause and as I had the same problem when using the keyword 'PRIORITY'. After modifying the C# code to use parameters, it worked.

using (OdbcCommand command = conn.CreateCommand())
{
   command.CommandText = "SELECT account_ref FROM SALES_LEDGER WHERE account_ref = '?'";
   command.Parameters.Add(new OdbcParameter("?", accountCode));

   using (OdbcDataReader reader = command.ExecuteReader())
   {
      ...
   }
}