c#批量更新list对象sql
注意:
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的更多相关文章
- 批量更新数据小心SQL触发器的陷阱
批量更新数据时候,Inserted和Deleted临时表也是批量的,但触发器只会调用执行一次!两个概念千万不要弄混淆! 错误的理解:例如:创建在A表上创建了一个Update触发器,里面写的是Updat ...
- Hibernate批量更新和批量删除批量添加(转)
通常,在一个Session对象的缓存中只存放数量有限的持久化对象,等到Session对象处理事务完毕,还要关闭Session对象,从而及时释放Session的缓存占用的内存.批量处理数据是指在一个事务 ...
- druid + mysql + mybatis 批量更新报错
首先 批量更新报错 sql injection violation, multi-statement not allow 然后看了博客:https://blog.csdn.net/qq_3634595 ...
- LINQ To SQL在N层应用程序中的CUD操作、批量删除、批量更新
原文:LINQ To SQL在N层应用程序中的CUD操作.批量删除.批量更新 0. 说明 Linq to Sql,以下简称L2S. 以下文中所指的两层和三层结构,分别如下图所示: 准确的说,这里 ...
- SQL 将2张不相关的表拼接成2列,批量更新至另一张表
update SO_Master set LotteryNo=t2.LotteryNo,UpdateTime=GETDATE() --select sm.LotteryNo,sm.SysNo,t2.L ...
- SQL批量更新数据库中所有用户数据表中字段类型为tinyint为int
--SQL批量更新数据库中所有用户数据表中字段类型为tinyint为int --关键说明:--1.从系统表syscolumns中的查询所有xtype='48'的记录得到类型为[tinyint]的字段- ...
- 高效批量更新 sql 字段的值(从一个表向另一个表更新)
里给出一种更高效.简洁的做法,批量更新SQL ,一句SQL就可以替代麻烦的循环过程,有MS SQLServer.Oracle.DB2下的写法--关键点:t4和t1是同一个table,primary k ...
- mybatis 的批量更新操作sql
转: mybatis 的批量更新操作sql 2018年07月23日 10:38:19 海力布 阅读数:1689 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.cs ...
- SQL批量更新数据
SQL批量更新数据 step1:导入Excel数据, 具体见百度.注意点:一列中含有float型数据和文本数据的时候,导入要将Excel中的表格属性改成文本,或在数字项目前加个单引号. step2 ...
随机推荐
- [Lua]弱引用table
参考链接: http://www.benmutou.com/archives/1808 一.强引用table lua中的table是引用类型,更准确地说,是强引用类型.如下第二段代码,在内存中有一个{ ...
- fabric Node SDK进行连接
yum install gcc-c++ npm install --unsafe-perm --registry=https://registry.npm.taobao.org chmod -R
- Mac技巧之苹果电脑Mac OS X系统自带的鼠标所在点颜色RGB值查看工具:数码测色计
转自http://www.mac52ipod.cn/post/show-mouse-point-rgb-color-by-apple-mac-os-x-tool.php
- RDD编程接口
Spark中提供了通用接口来抽象每个RDD,这些接口包括: 1.分区信息 2.依赖关系 3.函数,基于父RDD计算方法 4.划分策略和数据位置的元数据
- PHP AES加密解密。
<?php namespace app\models; class AES{ public $key; //构造函数,用密钥初始化 function Prpcrypt( $k ) { $this ...
- node-disconf-client基本配置
node-disconf-client 需要cppm install node-disconf-client var disconf = require (' node-disconf-clien ...
- APP-2-Hbuilder开发环境搭建
1.Hbuilder下载 http://www.dcloud.io/hbuilderx.html 2.夜神模拟器下载 https://www.yeshen.com/ 3.chrome浏览器下载 htt ...
- 配置tomcat的开发环境
第一步:鼠标右键计算机->属性->高级系统设置,进去之后,点击环境变量,如下图所示: 第二步:开始配置tomcat的环境变量,新建系统变量名CATALINA_BASE,值tomcat的安装 ...
- jquery查找筛选器
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- vue:绑定数据的vue页面加载会闪烁问题
1:在挂在数据的容器加上属性 v-cloak 2:在css中添加如下代码 但有时候还是会不起作用,可能原因有两个 2.1:display属性被更高权限的display属性覆盖了,我们增加权限就好了 2 ...