string sql = @"INSERT INTO stu VALUES (@id,@name) "; 参数化查询是经常用到的,它可以有效防止SQL注入.但是需要手动去匹配参数@id,@name.数据量大时很繁琐,下面是自动填充SqlParameter列表的实现. 支持泛型,Object和ExpandoObject动态类型 using System; using System.Collections.Generic; using System.Data.SqlClient; usin…
1.在更新DataTable或是DataSet时,如果不采用SqlParameter,那么当输入的Sql语句出现歧义时,如字符串中含有单引号,程序就会发生错误,并且他人可以轻易地通过拼接Sql语句来进行注入攻击. 2. string sql = "update Table1 set name = 'Pudding' where ID = '1'";//未采用SqlParameter SqlConnection conn = new SqlConnection(); conn.Conne…
Question: I' using Dapper in my project. I have a list of SqlParameters and I want to send it to Dapper. But Dapper needs an object (name, value). How can I convert a SqlParameter to an object. I know this doesn't work: conn.Query<TModel>(sql, param…
这是sqlHelper.cs类,类内里封装了方法 using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data; using System.Data.SqlClient; using System.Configuration; /// <summary> ///sqlHelper 的摘要说明 /// </summary> public cl…