1 /// <summary> 2 /// 执行多条SQL语句,实现数据库事务。 3 /// </summary> 4 /// <param name="SQLStringList">多条SQL语句</param> 5 public static void ExecuteSqlTran(ArrayList SQLStringList) 6 { 7 using (OracleConnection conn = new OracleConnection(connectionString)) 8 { 9 conn.Open(); 10 OracleCommand cmd = new OracleCommand(); 11 cmd.Connection=conn; 12 OracleTransaction tx=conn.BeginTransaction(); 13 cmd.Transaction=tx; 14 try 15 { 16 for(int n=0;n<SQLStringList.Count;n++) 17 { 18 string strsql=SQLStringList[n].ToString(); 19 if (strsql.Trim().Length>1) 20 { 21 cmd.CommandText=strsql; 22 cmd.ExecuteNonQuery(); 23 } 24 } 25 tx.Commit(); 26 } 27 catch(OracleException E) 28 { 29 tx.Rollback(); 30 throw new Exception(E.Message); 31 } 32 } 33 }