如何在db sql server中搜索包含特殊字符单引号 [英] How to search including special character single quotes in db sql server

查看:154
本文介绍了如何在db sql server中搜索包含特殊字符单引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从产品中选择* productname =框架:铝管C6 x 2 1/2法兰克斯170壁x 21'-0带粉末涂层





我的桌子



prodid productname



133框架:铝管C6 x 2 1/2Flangex 170墙x 21'-0带粉末涂层





错误:未关闭字符串'w / Powder Coat'后面的引号。

解决方案

简单的解决方案,不仅可以解决您当前的问题而且还可以补偿



- 如果您正在开发一个陌生人可以将输入保存到数据库中的应用程序,则可以避免潜在的SQL注入风险。



- 使你的代码更有条理,更易读:



SQL-Parameters。



此处示例:

http://www.dotnetperls.com/sqlparameter [ ^ ]



MSDN-Doc:

https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparameter%28v=vs.110%29.aspx [ ^ ]

Select * from product where productname="Frame: Aluminum Tube C6 x 2 1/2" Flangex 170" Wall x 21'-0" w/ Powder Coat"


My table

prodid productname

133 Frame: Aluminum Tube C6 x 2 1/2" Flangex 170" Wall x 21'-0" w/ Powder Coat


Error: Unclosed quotation mark after the character string ' w/ Powder Coat''.

解决方案

Simple solution, that not only remedies your current problem but also

- avoids the risk of potential SQL-Injection in case you're developing an application where strangers can make inputs that get saved into the database and

- makes your code more structured and better readable:

SQL-Parameters.

Example here:
http://www.dotnetperls.com/sqlparameter[^]

MSDN-Doc:
https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparameter%28v=vs.110%29.aspx[^]


这篇关于如何在db sql server中搜索包含特殊字符单引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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