c# 執(zhí)行事務(wù)函數(shù)代碼
更新時間:2009年05月14日 21:59:13 作者:
c#下 執(zhí)行多條sql語句,實現(xiàn)事務(wù)
復(fù)制代碼 代碼如下:
/// <summary>
/// 執(zhí)行多條sql語句,實現(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;
}
}
相關(guān)文章
Asp.net配合easyui實現(xiàn)返回json數(shù)據(jù)實例
這篇文章主要介紹了Asp.net配合easyui實現(xiàn)返回json數(shù)據(jù)的方法,實例分析了Asp.net配合easyui返回json數(shù)據(jù)時出現(xiàn)的問題及解決方法,非常具有實用價值的技巧,需要的朋友可以參考下2014-12-12
asp.net基礎(chǔ)學(xué)習(xí)之控件的使用方法
這篇文章主要為大家詳細(xì)介紹了asp.net基礎(chǔ)學(xué)習(xí)之控件的使用方法,感興趣的小伙伴們可以參考一下2016-08-08
ASP.NET技巧:請求網(wǎng)址并解析返回的html
ASP.NET技巧:請求網(wǎng)址并解析返回的html...2006-09-09
.NET6?ConfigurationManager的實現(xiàn)及使用方式
這篇文章主要介紹了.NET6?ConfigurationManager的實現(xiàn),我們上面展示的這一部分的ConfigurationManager代碼,其實就是替代了原來的ConfigurationBuilder類的功能,需要的朋友可以參考下2021-12-12
ASP.NET筆記之 ListView 與 DropDownList的使用
本篇文章小編為大家介紹,ASP.NET筆記之 ListView 與 DropDownList的使用。需要的朋友參考下2013-04-04

