注意:

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 开发 xml绘制shape与Selector与layer-list 一 基础篇

    首先我们先来了解状态效果 android:state_pressed=["true" | "false"]  按下状态 android:state_focuse ...

  2. Ruby学习笔记2 : 一个简单的Ruby网站,搭建ruby环境

    Ruby on Rails website 的基础是 请求-返回 循环. 首先是浏览器请求服务器, 第二步,Second, in our Rails application, the route ta ...

  3. pm2操作总结

    PM2是一个node.js的进程管理器,(并且呢在应用程序的生产运行时自带负载均衡的这种操作,很厉害): -->  pm2主要解决的问题是kill node进程时无法正常停止的问题. 主要特征: ...

  4. 最全的select加锁分析(Mysql)

    引言 大家在面试中有没遇到面试官问你下面六句Sql的区别呢 select * from table where id = ? select * from table where id < ? s ...

  5. 机器学习进阶-边缘检测-Canny边缘检测 1.cv2.Canny(进行Canny边缘检测)

    1. cv2.Canny(src, thresh1, thresh2) 进行canny边缘检测 参数说明: src表示输入的图片, thresh1表示最小阈值,thresh2表示最大阈值,用于进一步删 ...

  6. xlwt模块

    python使用xlwt模块操作Excel 该模块安装很简单 $ pip install xlwt 语法 import xlwt # 创建一个workbook 设置编码 workbook = xlwt ...

  7. MySQL 创建自定义函数

    语法:Create function function_name(参数列表)returns返回值类型 函数体 函数名,应合法的标识符,不应与系统关键字冲突. 一个函数应该属于某个数据库,可以使用db_ ...

  8. sourcetree 跳过注册

    https://www.cnblogs.com/lucio110/p/8192792.html

  9. python list元素为dict时的排序

    # 简单的dict lst = [('d', 2), ('a', 4), ('b', 3), ('c', 2)] # 按照value排序 lst.sort(key=lambda k: k[1]) pr ...

  10. 移动端取消touch高亮效果

    在做移动端页面时,会发现所有a标签在触发点击时或者所有设置了伪类 :active 的元素,默认都会在激活状态时,显示高亮框,如果不想要这个高亮,那么你可以通过css以下方法来禁止: .xxx{ -we ...