Python语言技术文档

微信小程序技术文档

php语言技术文档

jsp语言技术文档

asp语言技术文档

C#/.NET语言技术文档

html5/css技术文档

javascript

点击排行

您现在的位置:首页 > 技术文档 > C#/.NET技巧

c# 执行事务函数代码

来源:中文源码网    浏览:158 次    日期:2024-05-11 13:35:30
【下载文档:  c# 执行事务函数代码.txt 】


c# 执行事务函数代码
复制代码 代码如下:/// /// 执行多条sql语句,实现事务 /// /// 多条sql语句 public int ExecutrSqlTran(System.Collections.ArrayList arraySql) { int itemnum; DbOpen(); SqlCommand cm = new SqlCommand(); cm.Connection = scn; SqlTransaction tx = scn.BeginTransaction(); cm.Transaction = tx; try { for (int i = 0; i < arraySql.Count; i++) { string strSql = arraySql[i].ToString(); if (strSql.Trim().Length > 1) { cm.CommandText = strSql; cm.ExecuteNonQuery(); } } tx.Commit(); itemnum = 1; } catch (SqlException E) { tx.Rollback(); itemnum = 0; throw new Exception(E.Message); } DbClose(); return itemnum; } }

相关内容