手机
当前位置:查字典教程网 >编程开发 >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# 执行事务函数代码】相关文章:

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

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

asp.net保存远程图片的代码

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

Asp.Net(C#)自动执行计划任务的程序实例分析分享

C#中发送邮件代码

vs 不显示行号的操作方法

asp.net下模态对话框关闭之后继续执行服务器端代码的问题

asp.net(c#) RSS功能实现代码

sql事务应用积累

精品推荐
分类导航