日期:2014-05-17 浏览次数:20380 次
protected void Button1_Click(object sender, EventArgs e) { try { //其他代码 OracleConnection conn = new OracleConnection(ConnectionString); OracleTransaction transaction = null; OracleCommand cmd = null; try { conn.Open(); transaction = conn.BeginTransaction();//事务开始 cmd = conn.CreateCommand(); cmd.CommandText = "insert into table1 (name) values ('abc')"; cmd.Transaction = transaction; cmd.ExecuteNonQuery(); transaction.Commit();//提交 Response.Redirect("index.aspx"); } catch { transaction.Rollback();//回滚 } finally { if (cmd != null) cmd.Dispose(); if (conn != null) { conn.Close(); conn.Dispose(); } } } catch (Exception ex) { } }