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# 执行事务函数代码就介绍到这了。就算你看不清明天的路,也要放手为今天而拼博。更多相关c# 执行事务函数代码内容请查看相关栏目,小编编辑不易,再次感谢大家的支持!