源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

c# 执行事务函数代码

  • 时间:2022-03-15 20:32 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:c# 执行事务函数代码
[u]复制代码[/u] 代码如下:
/// <summary> /// 执行多条sql语句,实现事务 /// </summary> /// <param name="arraySql">多条sql语句</param> 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; } }
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部