使用CONTAINS和变量中的短语进行全文查询(csharp; sql)

时间:2015-04-21 09:26:08

标签: c# sql asp.net

我想问一下,如果我有这样的代码,我需要使用哪些引号:

cSQL += "CONTAINS (sectionArticleTitle, @SearchText) ";

例如,

如果我有变量SearchText短语“with the”(没有引号),我需要查询:

SELECT * FROM ...... WHERE CONTAINS (sectionArticleTitle, '"with the"');

所以我想知道我应该如何在cSQL变量中添加引号。如果我使用

,我会收到语法错误
cSQL += "CONTAINS (sectionArticleTitle, '"@SearchText"') ";

非常感谢。

1 个答案:

答案 0 :(得分:0)

单引号可以解决问题。尝试以下代码:

cSQL+=string.Format(@"SELECT * FROM CONTAINS(sectionArticleTitle,'""{0}""')", @SearchText);