注意:

1.语句中"set "后有空格,

2.最后一个if一定有值,且接连的sql字段 无  逗号

3.parameterList.Clear();

 /// <summary>
        /// 批量更新
        /// </summary>
        public void UpdateList(List<ProModule.Model.ept_scn> list)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update ept_scn set ");

            List<MySqlParameter> parameterList = new List<MySqlParameter>();

            int x = list.Count;
            Hashtable SQLStringList = new Hashtable();
            for (int i = 0; i < x; i++)
            {
                ProModule.Model.ept_scn scn = list[i];
                int y = 0;
                if (scn.scn != null)
                {
                    strSql.Append("scn=@scn,");
                    parameterList.Add(new MySqlParameter("@scn", MySqlDbType.VarChar, 50));
                    parameterList[y].Value = scn.scn;
                    y = y + 1;
                }
                if (scn.is_lock != null)
                {
                    strSql.Append("is_lock=@is_lock,");
                    parameterList.Add(new MySqlParameter("@is_lock", MySqlDbType.Int32, 11));
                    parameterList[y].Value = scn.is_lock;
                    y = y + 1;
                }
                if (scn.is_audit != null)
                {
                    strSql.Append("is_audit=@is_audit,");
                    parameterList.Add(new MySqlParameter("@is_audit", MySqlDbType.Int32, 11));
                    parameterList[y].Value = scn.is_audit;
                    y = y + 1;
                }
                if (scn.is_abandon != null)
                {
                    strSql.Append("is_abandon=@is_abandon,");
                    parameterList.Add(new MySqlParameter("@is_abandon", MySqlDbType.Int32, 11));
                    parameterList[y].Value = scn.is_abandon;
                    y = y + 1;
                }
                if (scn.is_finish != null)
                {
                    strSql.Append("is_finish=@is_finish,");
                    parameterList.Add(new MySqlParameter("@is_finish", MySqlDbType.Int32, 11));
                    parameterList[y].Value = scn.is_finish;
                    y = y + 1;
                }
                if (scn.remark != null)
                {
                    strSql.Append("remark=@remark,");
                    parameterList.Add(new MySqlParameter("@remark", MySqlDbType.VarChar, 50));
                    parameterList[y].Value = scn.remark;
                    y = y + 1;
                }

                if (scn.msg != null)
                {
                    strSql.Append("msg=@msg,");
                    parameterList.Add(new MySqlParameter("@msg", MySqlDbType.VarChar, 50));
                    parameterList[y].Value = scn.msg;
                    y = y + 1;
                }
                if (scn.audit_by != null)
                {
                    strSql.Append("audit_by=@audit_by,");
                    parameterList.Add(new MySqlParameter("@audit_by", MySqlDbType.VarChar, 50));
                    parameterList[y].Value = scn.audit_by;
                    y = y + 1;
                }
                if (scn.audit_time != null)
                {
                    strSql.Append("audit_time=@audit_time,");
                    parameterList.Add(new MySqlParameter("@audit_time", MySqlDbType.DateTime));
                    parameterList[y].Value = scn.audit_time;
                    y = y + 1;
                }
                if (scn.checks != null)
                {
                    strSql.Append("checks=@checks");
                    parameterList.Add(new MySqlParameter("@checks", MySqlDbType.Int32, 11));
                    parameterList[y].Value = scn.checks;
                    y = y + 1;
                }
                strSql.Append(" where id=@id ");
                parameterList.Add(new MySqlParameter("@id", MySqlDbType.VarChar, 50));
                parameterList[y].Value = scn.id;
                MySqlParameter[] parameters = parameterList.ToArray(); ;
                SQLStringList.Add(strSql.ToString(), parameters);
                parameterList.Clear();
            }
            DbHelperMySQL.ExecuteSqlTran(SQLStringList);
        }

  

c#批量更新list对象sql的更多相关文章

  1. 批量更新数据小心SQL触发器的陷阱

    批量更新数据时候,Inserted和Deleted临时表也是批量的,但触发器只会调用执行一次!两个概念千万不要弄混淆! 错误的理解:例如:创建在A表上创建了一个Update触发器,里面写的是Updat ...

  2. Hibernate批量更新和批量删除批量添加(转)

    通常,在一个Session对象的缓存中只存放数量有限的持久化对象,等到Session对象处理事务完毕,还要关闭Session对象,从而及时释放Session的缓存占用的内存.批量处理数据是指在一个事务 ...

  3. druid + mysql + mybatis 批量更新报错

    首先 批量更新报错 sql injection violation, multi-statement not allow 然后看了博客:https://blog.csdn.net/qq_3634595 ...

  4. LINQ To SQL在N层应用程序中的CUD操作、批量删除、批量更新

    原文:LINQ To SQL在N层应用程序中的CUD操作.批量删除.批量更新 0. 说明 Linq to Sql,以下简称L2S.    以下文中所指的两层和三层结构,分别如下图所示: 准确的说,这里 ...

  5. SQL 将2张不相关的表拼接成2列,批量更新至另一张表

    update SO_Master set LotteryNo=t2.LotteryNo,UpdateTime=GETDATE() --select sm.LotteryNo,sm.SysNo,t2.L ...

  6. SQL批量更新数据库中所有用户数据表中字段类型为tinyint为int

    --SQL批量更新数据库中所有用户数据表中字段类型为tinyint为int --关键说明:--1.从系统表syscolumns中的查询所有xtype='48'的记录得到类型为[tinyint]的字段- ...

  7. 高效批量更新 sql 字段的值(从一个表向另一个表更新)

    里给出一种更高效.简洁的做法,批量更新SQL ,一句SQL就可以替代麻烦的循环过程,有MS SQLServer.Oracle.DB2下的写法--关键点:t4和t1是同一个table,primary k ...

  8. mybatis 的批量更新操作sql

    转: mybatis 的批量更新操作sql 2018年07月23日 10:38:19 海力布 阅读数:1689   版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.cs ...

  9. SQL批量更新数据

    SQL批量更新数据 step1:导入Excel数据, 具体见百度.注意点:一列中含有float型数据和文本数据的时候,导入要将Excel中的表格属性改成文本,或在数字项目前加个单引号.   step2 ...

随机推荐

  1. android 开发 实现一个进入相机拍照后裁剪图片或者进入相册选中裁剪图片的功能

    实现思维路径: 以进入相机拍照的思维路线为例子: 1.进入app 2.判断之前是否保存头像,如果有就显示历史图像 (下面代码中在getOldAvatar();方法中执行这个逻辑) 3.点击更换图像的B ...

  2. access oarcle

    1 默认值2 自动增加字段3 now() time() date() 更改sysdate4 datediff5 保留字 date 名字段6isnull(rowname)要改成rowname = nul ...

  3. SVG:中国地图

    中国地图 <svg height="578" version="1.1" width="718" xmlns="http:/ ...

  4. css:蓝环章鱼

    许多海洋生物色彩艳丽,这次用css仿制一下蓝环章鱼的蓝环 <script type="text/javascript" src="http://cdn.bootcs ...

  5. Mybatis学习4——核心文件sqlMapperConfig.xml属性

    1.外部文件jdbc.properties jdbc.driver=com.mysql.jdbc.Driver jdbc.url=jdbc:mysql://localhost:3306/mybatis ...

  6. windows server 域分发与分配软件

    参考网站:https://blog.csdn.net/southwind0/article/details/80734508 1.win 2008创建域 https://jingyan.baidu.c ...

  7. 17. 判断是否IE浏览器

    var isNotIE = !window.VBArray;    //判断是否IE浏览器    if(isNotIE) {        //如果不是IE浏览器        $("#da ...

  8. Spring MVC 的springMVC.xml疑问解析

    <mvc:annotation-driven /> <mvc:annotation-driven /> 会自动注册DefaultAnnotationHandlerMapping ...

  9. Linux查看系统中socket状态

    当我们打开的socket数量很多时,netstat就会变得慢了,有什么办法可以快速查看系统中socket状态? IPv4: $ cat /proc/net/sockstat sockets: used ...

  10. python 之列表推导式,集合推导式,以及字典推导式

    https://www.cnblogs.com/weihengblog/p/8428124.html