在SQL查询转义值(C#与SQL连接器) [英] Escaping values in SQL queries (C# with SQL connector)

查看:153
本文介绍了在SQL查询转义值(C#与SQL连接器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以使用的参数,但什么是逃串序列的正确方法?
中的查询可以是这样的:

I know I can use the parameters, but what is the right way to escape string sequences? The query could be like this:

"INSERT INTO records (ReferenceID,Name,Note,Author) VALUES ('" + ID+ "','" + addlevel.textBox1.Text + "','"+addlevel.textBox2_note.Text+ "','"+Program.Username+"')";



我只是好奇,只是想知道:)

I am ONLY curious, just want to know :)

编辑:
可是你知道吗?
CREATE TABLE+字符串....参数不能用在这里!

But what about that? "CREATE TABLE "+string" .... parameters cannot be used here!

推荐答案

如果您需要执行数据库操作,如创建表,那么你应该使用 SQL Server管理对象不是执行的。SQL字符串

If you need to perform database operations, such as creating tables, then you should use SQL Server Management Objects instead of executing SQL strings.

有关CRUD操作参数是绝对的唯一正确道路。

For CRUD operations parameters is absolutely the only true path.

更新:看来, MySQL客户端库包含此不明智的任务一个辅助方法,你可以调用MySqlHelper.EscapeString(字符串)。

UPDATE: It appears that the MySQL client library contains a helper method for this ill-advised task. You can call MySqlHelper.EscapeString(string).

这篇关于在SQL查询转义值(C#与SQL连接器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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