-
实现事务处理.
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
/**//// <summary>
/// 执行多条SQL语句,实现数据库事务。
/// </summary>
/// <param name="SQLStringList">多条SQL语句</param>
public static void ExecuteTransaction(ArrayList SQLStringList)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
...{
using (SqlConnection conn = new SqlConnection(connectionString))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection=conn;
SqlTransaction tx=conn.BeginTransaction();
cmd.Transaction=tx;
try
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
for(int n=0;n<SQLStringList.Count;n++)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
string strsql=SQLStringList[n].ToString();
if (strsql.Trim().Length>1)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
cmd.CommandText=strsql;
cmd.ExecuteNonQuery();
}
}
tx.Commit();
}
catch(System.Data.SqlClient.SqlException E)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
...{
tx.Rollback();
throw new Exception(E.Message);
}
}
}
-
相关阅读:
php函数
字符滚动效果0515复习笔记+注释
0514复习Windows操作及DOM的使用
超链接文字随状态改变变色2016-0514
js笔记之影音插入0514
js类型转换,运算符,语句
JS学习1简介
json文件的json.parse(data)方法时候碰到的问题
样式属性
css样式表0513补
-
原文地址:https://www.cnblogs.com/xiaotuni/p/2365749.html
Copyright © 2020-2023
润新知