在字符串中包含“或”时出现语法错误

时间:2012-07-27 12:15:51

标签: c# sql sql-server irony

我目前正在使用反讽作为我搜索过程的一部分(不是我的选择而且我没有发言权:P)并且使用字母组合“或”后跟空格和另一个单词存在问题,IE“Orbit Gum”但是,如果你搜索“轨道”之类的东西,或仅仅是“或”,它似乎工作正常。

发生的错误是

Syntax error near 'gum' in the full-text search condition 'orbit gum'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Syntax error near 'gum' in the full-text search condition 'orbit gum'.

用于生成此部分的代码是

        //Union with the full text search
        if (!string.IsNullOrEmpty(fTextSearch))
            {
                sql.AppendLine("UNION");
                sql.AppendLine(commonClause);
                sql.AppendLine(string.Format("AND CONTAINS(nt.text, '{0}', LANGUAGE 'English')", fTextSearch));
            }

就我所见,导致问题的实际查询就是这一行:

AND CONTAINS(nt.text, 'orbit gum', LANGUAGE 'English')

0 个答案:

没有答案
相关问题