ODBC SQL,在where子句中使用保留字 [英] ODBC SQL, Using a reserved word in a where clause

查看:365
本文介绍了ODBC SQL,在where子句中使用保留字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我需要在ODBC中搜索一个保留字的值. 所以:

I have a problem where I need to search for a value in a ODBC which is a reserved word. So:

SELECT * FROM Customer WHERE AccountNumber = 'Sum'

在这种情况下,"Sum"是保留字,因此出现语法错误. 在访问中,错误为"SELECT语句包含一个保留字或一个拼写错误或丢失的参数名称,或者标点符号不正确"

In this case, 'Sum' is a reserved word and so I get a syntax error. In access the error is "The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect"

有没有办法搜索这样的字符串?

Is there a way I can search for such a string?

推荐答案

参数化您希望用作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())
   {
      ...
   }
}

这篇关于ODBC SQL,在where子句中使用保留字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆