SQL在C#源码逃生 [英] SQL escape with sqlite in C#

查看:113
本文介绍了SQL在C#源码逃生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本字段,其打破我的sql语句。我如何逃脱在这一领域的所有字符?我在C#

I have a text field and its breaking my sql statement. How do i escape all the chars in that field? I am using sqlite with http://sqlite.phxsoftware.com/ in C#

推荐答案

您应该使用的参数为:

SQLiteCommand cmd = _connection.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT * FROM MyTable WHERE MyColumn = @parameter";
cmd.Parameters.Add( new SQLiteParameter( "@parameter", textfield ) );
SQLiteDataReader reader = cmd.ExecuteReader();



使用parametrised SQL将转义所有的输入值,并帮助您防止SQL注入攻击。

Using a parametrised SQL will escape all input values and help protect you from SQL injection attacks.

这篇关于SQL在C#源码逃生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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