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 ...
随机推荐
- 《算法》第六章部分程序 part 3
▶ 书中第六章部分程序,包括在加上自己补充的代码,后缀树的两种实现 ● 后缀树实现一 package package01; import java.util.Arrays; import edu.pr ...
- web.xml配置重理解
<context-param> <param-name>home-page</param-name> <param-value>home.jsp< ...
- 【ASP.NET 插件】分享一个可视化HTML编辑器 CKEditor.NET
因为公司网站的可视化HTML编辑器IE兼容性问题,js报错不能使用,于是在网上找到了个还行的,图片本地上传的话直接把图片拖到编辑窗口就可以了.这个编辑器是在开源中国看到的,个人觉得还不错! CKEdi ...
- js 在光标位置插入内容
原文:https://blog.csdn.net/smartsmile2012/article/details/53642082 createDocumentFragment()用法: https:/ ...
- WPF ListView即时更新
1.ListView 的 ItemSource 使用 BindingList < T >: 注:由于 List < T > 没有实现 INotifyPropertyChange ...
- elasticsearch-java
elastissearch的JAVA客户端 官网 java api文档 https://www.elastic.co/guide/en/elasticsearch/client/java-api/ ...
- 集合,ArrayList
用集合代替数组: Console.Write("请输入人数:"); int renshu = int.Parse(Console.ReadLine()); ArrayList ch ...
- cordova-config.xml配置应用图标
1. <icon src="res/icon/ios/browser.png"/> 2.规格: iphone平台一般要求3种规格的图片:1x.2x.3x,也是就Icon ...
- js 迭代器 解说
这里要说的是迭代器,是一种思路而已,代码相对来不是最关键的,个人认为,最关键的部分是实现的思路 要求: 在一个网页中,将所有的 p 元素的内容进行替换,但是在特定的位置的 p 元素是要有差异的进行替换 ...
- 把网卡中断绑定到CPU,最大化网卡的吞吐量(转)
先来看一下问题, 我们通过 ifconfig 查看接口的名称 为 p15p1, 一般机器为 eth0 再通过命令 ➜ ~ cat /proc/interrupts | head -n 1 && ...