C# sql搜索中如何识别和转义撇号
我的C程序中有sql查询来搜索或过滤一些记录。当我用撇号传递字符串值时,它会在我的C程序中抛出一些不正确的关键字错误 我的示例输入 我的问题C# sql搜索中如何识别和转义撇号,c#,sql-server,C#,Sql Server,我的C程序中有sql查询来搜索或过滤一些记录。当我用撇号传递字符串值时,它会在我的C程序中抛出一些不正确的关键字错误 我的示例输入 我的问题 感谢您在提供解决方案方面提供的任何帮助 您只需转义单引号即可 在语句中插入“Val”之前,请执行以下操作: Val=Val.Replace' 最好的解决方案是使用SqlParameter并防止sql注入。 String Val= Tests of the 'convergence hypothesis' : a critical note / Dani
感谢您在提供解决方案方面提供的任何帮助 您只需转义单引号即可 在语句中插入“Val”之前,请执行以下操作: Val=Val.Replace' 最好的解决方案是使用SqlParameter并防止sql注入。
String Val= Tests of the 'convergence hypothesis' : a critical note / Daniel Cohen.
string MySqlQry="SELECT bc.BibId,
stuff(
(SELECT ' ' + bsc.NormValue + ''
FROM BibContents bsc
WHERE bsc.bibid = bc.bibid
AND bsc.tagno = '245'
ORDER BY bsc.Sfld
FOR xml path(''), root('MyString'), TYPE).value('/MyString[1]','varchar(max)') , 1, 1, '') AS Title,
stuff(
(SELECT ' ' + bsc.NormValue + ''
FROM BibContents bsc
WHERE bsc.bibid = bc.bibid
AND bsc.tagno = '020'
ORDER BY bsc.Sfld
FOR xml path(''), root('MyString'), TYPE).value('/MyString[1]','varchar(max)') , 1, 1, '') AS ISBN,
stuff(
(SELECT ' ' + bsc.NormValue + ''
FROM BibContents bsc
WHERE bsc.bibid = bc.bibid
AND bsc.tagno = '250'
ORDER BY bsc.Sfld
FOR xml path(''), root('MyString'), TYPE).value('/MyString[1]','varchar(max)') , 1, 1, '') AS Edition,
stuff(
(SELECT ' ' + bsc.NormValue + ''
FROM BibContents bsc
WHERE bsc.bibid = bc.bibid
AND bsc.tagno = '260'
ORDER BY bsc.Sfld
FOR xml path(''), root('MyString'), TYPE).value('/MyString[1]','varchar(max)') , 1, 1, '') AS Publisher,
(SELECT top(1) Value FROM BibContents
WHERE TagNo='100'
AND Sfld='a'
AND BibId=bc.BibId) AS Author
FROM BibContents bc
WHERE (bc.NormValue LIKE '" + Val + "%'
OR bc.NormValue LIKE '% " + Val + "%')
AND bc.TagNo='245'";
model = db.ExecuteStoreQuery<PoDetails>(MySqlQry).ToList();