简体   繁体   English

在ASP.NET Web搜索中如何处理单引号

[英]How do you handle a single quote in an asp.net web search

How do you handle special characters in an asp.net web search with SQL Server back end database. 如何使用SQL Server后端数据库处理asp.net Web搜索中的特殊字符。 For example, single quotes and double quotes, etc. 例如,单引号和双引号等。

Replacing the single quote ' or double quotes " would be done like this 更换单引号'或双引号"就这样进行

StrQuery = "Select * from TableName Where Keyword LIKE '%" + TxtSearchBox.Text + "%'";
StrQuery = StrQuery.Replace("'", "\'");
StrQuery = StrQuery.Replace('"', "\"");
StrQuery = StrQuery.Replace("\", "\\");

Another very important thing is you'd be better off using Parameterized queries . 另一个非常重要的事情是,使用参数化查询会更好。 These will automatically handle the single quotes, and protect you better from SQL Injection. 这些将自动处理单引号,并更好地保护您免受SQL Injection。

SET QUOTED_IDENTIFIER would follow the ISO rules regarding quotation mark delimiting identifiers and literal strings. SET QUOTED_IDENTIFIER将遵循有关引号定界标识符和文字字符串的ISO规则。 Identifiers delimited by double quotation marks can be either Transact-SQL reserved keywords or can contain characters not generally allowed by the Transact-SQL syntax rules for identifiers. 用双引号引起来的标识符可以是Transact-SQL保留关键字,也可以包含Transact-SQL语法规则通常不允许使用的字符作为标识符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在ASP.NET C#中替换单引号 - How to replace single quote in asp.net c# ASP.NET中的单引号(')和双引号(“)奇怪的行为 - Single quote(') and double quote (") strange behavior in ASP.NET asp.net web forms .net 4.8 这个加载进度是怎么做到的 - How do you do this loading progress in asp.net web forms .net 4.8 您将如何在单个ASP.Net MVC Web应用程序中构建访问者和管理员功能? - How would you architect visitor and admin functions in a single ASP.Net MVC web application? 如何在带有母版页的单个ASP.NET页中使用2个按钮进行验证? - How do you do validation with 2 buttons in a single ASP.NET page with masterpage? 如何处理ASP.NET MVC中的多部分表单? - How do you handle multi-part forms in ASP.NET MVC? 你如何处理 ASP.NET MVC 框架中的多个提交按钮? - How do you handle multiple submit buttons in ASP.NET MVC Framework? 如何编写一种方法来处理ASP.NET中高级搜索功能的所有排列? - How do I write one method to handle all permutations of an advanced search feature in ASP.NET? 如何对ASP.NET核心Web应用程序(.Net Framework)进行单元测试? - How do you unit test ASP.NET Core Web Application (.Net Framework)? 如何在ASP.net Web窗体应用程序中处理False / Empty查询? - How do I handle False/Empty query's in a ASP.net Web forms App?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM