当前位置: 移动技术网 > IT编程>开发语言>.net > c# 执行事务函数代码

c# 执行事务函数代码

2017年12月12日  | 移动技术网IT编程  | 我要评论

锯片清洗机,红寨论坛,异世之御剑逍遥仙

复制代码 代码如下:

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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网