復(fù)制代碼 代碼如下:
/// <summary>
/// 執(zhí)行多條sql語(yǔ)句,實(shí)現(xiàn)事務(wù)
/// </summary>
/// <param>多條sql語(yǔ)句</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;
}
}
新聞熱點(diǎn)
疑難解答
圖片精選