手机
当前位置:查字典教程网 >编程开发 >asp.net教程 >c# 执行事务函数代码
c# 执行事务函数代码
摘要:复制代码代码如下://////执行多条sql语句,实现事务//////多条sql语句publicintExecutrSqlTran(Syst...

复制代码 代码如下:

/// <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# 执行事务函数代码】相关文章:

aspx 中文汉字显示为乱码

C#默认以管理员身份运行程序实现代码

.NET(C#)连接各类数据库代码-集锦

Asp.NET 多层登陆实现代码

.Net读取Excel 返回DataTable实例代码

ASP.net 验证码实现代码(C#)

Asp.Net常用函数

sql事务应用积累

asp.net 操作excel的实现代码

.net发送邮件实现代码

精品推荐
分类导航