分类:
2008-10-28 10:12:54
////// 执行多条SQL语句,实现数据库事务。 /// /// 多条SQL语句 public static void ExecuteSqlTran(ArrayList SQLStringList) { using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); SqlCommand cmd = new SqlCommand(); cmd.Connection=conn; SqlTransaction tx=conn.BeginTransaction(); cmd.Transaction=tx; try { for(int n=0;n1) { cmd.CommandText=strsql; cmd.ExecuteNonQuery(); } } tx.Commit(); } catch(System.Data.SqlClient.SqlException E) { tx.Rollback(); throw new Exception(E.Message); } } }