如何在 VB.net 中为 SQL 编码字符串
例如,在sql中
所有`应该替换为``,对吧?
那么,vb.net 是否已经内置了一个可以完成此类操作的函数?
这样我就不必对其进行编码。
顺便说一句,我不直接访问sql数据库。基本上我正在创建一个文本文件,该文本文件包含原始 sql 语句。大多数答案都涉及直接访问 sql 数据。
For example, in sql
all ` should be replaced with `` right?
Well, is there a function built in by vb.net that does that sort of thing already?
That way I do not have to encode it.
By the way, I do not access sql database directly. Basically I am creating a text file and that text file contains raw sql statements. Most of the answers deal with accessing sql data directly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不这么认为,因为我认为唯一与此相关的情况是您执行不带参数的内联 SQL 命令。
这存在 SQL 注入 的风险,因此您应该创建如下命令:
I don't think so as I think the only case where something like this would be relevant is if you were doing inline SQL Commands without parameters.
This has a risk of SQL Injection, and therefore you should create commands like this:
不要尝试这样做!我知道您正在努力避免 SQL 注入,因此您对安全性的考虑值得赞扬。然而,自行执行消毒程序很容易出错。
在查询中使用以下参数
Dont try and do this! I know you are trying to avoid SQL Injection so you are to be commended for thinking about security. However rolling your own sanitisation routine is something that is easy to get wrong.
Use parameters in your query along the lines of
如果您使用
字符串
,那么您将在代码中使用"
,这样您就不需要转义这些字符。If you are using a
string
then you'll be using"
in your code so you won't need to escape these characters.