c# 執(zhí)行事務(wù)函數(shù)代碼
來源:懂視網(wǎng)
責(zé)編:小采
時(shí)間:2020-11-27 22:44:20
c# 執(zhí)行事務(wù)函數(shù)代碼
c# 執(zhí)行事務(wù)函數(shù)代碼: 代碼如下:/// <summary> /// 執(zhí)行多條sql語句,實(shí)現(xiàn)事務(wù) /// </summary> /// <param name=arraySql>多條sql語句</param> public int ExecutrSqlTran(System.Collections.Arra
導(dǎo)讀c# 執(zhí)行事務(wù)函數(shù)代碼: 代碼如下:/// <summary> /// 執(zhí)行多條sql語句,實(shí)現(xiàn)事務(wù) /// </summary> /// <param name=arraySql>多條sql語句</param> public int ExecutrSqlTran(System.Collections.Arra
代碼如下:
/// <summary>
/// 執(zhí)行多條sql語句,實(shí)現(xiàn)事務(wù)
/// </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;
}
}
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
c# 執(zhí)行事務(wù)函數(shù)代碼
c# 執(zhí)行事務(wù)函數(shù)代碼: 代碼如下:/// <summary> /// 執(zhí)行多條sql語句,實(shí)現(xiàn)事務(wù) /// </summary> /// <param name=arraySql>多條sql語句</param> public int ExecutrSqlTran(System.Collections.Arra