(C#)执行多条SQL语句,事务处理
2008-09-07 16:57
716 查看
///
/// 执行多条SQL语句,事务处理
///
/// 以";"相隔的查询语句
public bool InsertMoreDB(string strSQL){
char[] de={’;’};
string strChildSQL;
int i;
string[] strSQLArr=strSQL.Split(de);
bool IsControll=true;
SqlConnection conn=DBCreateCN();
SqlCommand myCommand=new SqlCommand();
SqlTransaction myTrans;
myTrans=conn.BeginTransaction();
myCommand.Connection = conn;
myCommand.Transaction = myTrans;
try
{
for(i=0;i
{
strChildSQL=strSQLArr[i];
myCommand.CommandText =strChildSQL;
myCommand.ExecuteNonQuery();
}
myTrans.Commit();
IsControll=true;
}
catch(Exception)
{
try
{
IsControll=false;
myTrans.Rollback();
}
catch (SqlException)
{
// Handle possible exception here
}
}
finally
{
conn.Close();
}
return IsControll;
}
/// 执行多条SQL语句,事务处理
///
/// 以";"相隔的查询语句
public bool InsertMoreDB(string strSQL){
char[] de={’;’};
string strChildSQL;
int i;
string[] strSQLArr=strSQL.Split(de);
bool IsControll=true;
SqlConnection conn=DBCreateCN();
SqlCommand myCommand=new SqlCommand();
SqlTransaction myTrans;
myTrans=conn.BeginTransaction();
myCommand.Connection = conn;
myCommand.Transaction = myTrans;
try
{
for(i=0;i
{
strChildSQL=strSQLArr[i];
myCommand.CommandText =strChildSQL;
myCommand.ExecuteNonQuery();
}
myTrans.Commit();
IsControll=true;
}
catch(Exception)
{
try
{
IsControll=false;
myTrans.Rollback();
}
catch (SqlException)
{
// Handle possible exception here
}
}
finally
{
conn.Close();
}
return IsControll;
}
相关文章推荐
- JAVA中处理事务的程序--多条更新SQL语句的执行(包括回滚)
- JAVA中处理事务的程序--多条更新SQL语句的执行(包括回滚) .
- JAVA中处理事务的程序--多条更新SQL语句的执行(包括回滚) .
- C# 执行多条SQL更新语句,实现数据库事务
- JAVA中处理事务的程序--多条更新SQL语句的执行(包括回滚)
- C# 批量执行 sql语句 事务 参数
- c# 数据库访问静态类 支持多条SQL语句事务操作
- C#实现执行多条SQl语句,实现数据库事务
- 在EF4.1的DBContext中实现事务处理(BeginTransaction)和直接执行SQL语句的示例
- 在EF4.1的DBContext中实现事务处理(BeginTransaction)和直接执行SQL语句的示例
- 关于 sql server 客户端执行多条sql语句事务的问题
- 在EF4.1的DBContext中实现事务处理(BeginTransaction)和直接执行SQL语句的示例
- C# 执行多条SQL语句,实现数据库事务(通过Hashtable存储数据) .
- 在EF4.1的DBContext中实现事务处理(BeginTransaction)和直接执行SQL语句的示例
- [置顶] c# 执行多条SQL语句,实现数据库事务 线性表 Hashtable
- C#执行Sql事务处理
- 使用事务一次处理多条SQL语句
- C# 一次执行多条SQL语句,Oracle11g数据库
- c# 执行多条SQL语句,实现数据库事务 线性表 Hashtable
- ORACLE DML LOCK时找出对应SESSION正在执行的SQL语句(ORA-12841,无法变更事务处理中的会话并行 DML 状态)