mysql_real_escape_string()在.NET框架 [英] mysql_real_escape_string() in .NET Framework

查看:119
本文介绍了mysql_real_escape_string()在.NET框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想找到在.NET框架中的函数来调用SQL-Server的转义真正发送到SQL Server,为的 mysql的实时​​转义字符串()调用MySQL的库做PHP。
请提出,我可以调用它的方法,它通过一个往返数据库返回转义字符串,没有必要FO执行它的查询
有吗?

i want to find a function in .NET framework to calls SQL-Server's library for escaping really a value for sending to sql server, as mysql-real-escape-string() calls MySQL's library to do in PHP.
please propose a method that i can call it and it return escaped string via one round-trip to database, no need fo executing It's query
Is there it?

推荐答案

你为什么要这么做?发送用户输入到数据库中的正确方法是不是逃避它,但使用的查询参数的。

Why do you want to do that? The correct way to send user input to the database is not to escape it, but to use query parameters.

using(var command = new SqlCommand("insert into MyTable(X, Y) values(@x, @y)", connection))
{
    command.Parameters.Add("@x", textBoxX.Text);
    command.Parameters.Add("@y", textBoxY.Text);
    command.ExecuteNonQuery();
}

此提供了更好的性能,因为查询文本总是相同的,所以查询执行计划可以被缓存。这也可以让你免受SQL注入攻击。而且它也可以让你忽略的数据格式问题(如日期时间的格式设置SQL服务器?你应该如何重新present一些在SQL?等等)

This provides better performance, because the query text is always the same so the query execution plan can be cached. This also protects you against SQL injection attacks. And it also allows you to ignore data formatting issues (e.g. how is a DateTime formatted in SQL-Server? How should you represent a number in SQL? and so on)

这篇关于mysql_real_escape_string()在.NET框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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