CXYVIP官网源码交易平台_网站源码_商城源码_小程序源码平台-丞旭猿论坛
CXYVIP官网源码交易平台_网站源码_商城源码_小程序源码平台-丞旭猿论坛
CXYVIP官网源码交易平台_网站源码_商城源码_小程序源码平台-丞旭猿论坛

c# 执行事务函数代码

实现代码如下:

/// <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;
}
}

以上就是【c# 执行事务函数代码】的全部内容了,欢迎留言评论进行交流!

© 版权声明
THE END
喜欢就支持一下吧
点赞0赞赏 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容