当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > 在数据库中开始一个事务。

ASP.NET
aspnet_regsql不能在sql2005下使用的解决
.NET发送邮件
让.Net验证控件与自定义验证合作无间
给.Net程序员和WEB程序员建议:.Net篇
给.Net程序员和WEB程序员建议:WEB篇
Server Application Unavailable错误解决方法
ASP.NET AJAX:UpdatePanel控件
ASP.NET教程:Ref和Out关键字异同
组件Newtonsoft.Json实现object2json转换
ASP.NET教程:Control基类清理页面状态
ASP.NET入门教程:认识ASP.NET
ASP.NET入门教程:ASP.NET和ASP区别
ASP.NET入门教程:简单的ASP.NET页面
ASP.NET入门教程:服务器控件
ASP.NET入门教程:事件句柄
ASP.NET入门教程:Web表单
ASP.NET入门教程:Web表单维持对象的ViewState
ASP.NET入门教程:TextBox控件
ASP.NET入门教程:Button控件
ASP.NET入门教程:数据绑定

ASP.NET 中的 在数据库中开始一个事务。


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 84 ::
收藏到网摘: n/a


下面的示例创建一个 OracleConnection 和一个 OracleTransaction。它还演示了如何使用 BeginTransaction、Commit 和 Rollback 方法。
public void RunOracleTransaction(string myConnString){ OracleConnection myConnection = new OracleConnection(myConnString); myConnection.Open();
OracleCommand myCommand = myConnection.CreateCommand(); OracleTransaction myTrans;
// Start a local transaction myTrans = myConnection.BeginTransaction(IsolationLevel.ReadCommitted); // Assign transaction object for a pending local transaction myCommand.Transaction = myTrans;
try { myCommand.CommandText = "INSERT INTO Dept (DeptNo, Dname, Loc) values (50, 'TECHNOLOGY', 'DENVER')"; myCommand.ExecuteNonQuery(); myCommand.CommandType= CommandType.StoredProcedure; myCommand.CommandText="prc_test"; myCommand.ExecuteNonQuery(); myTrans.Commit(); Console.WriteLine("Both records are written to database."); } catch(Exception e) { myTrans.Rollback(); Console.WriteLine(e.ToString()); Console.WriteLine("Neither record was written to database."); } finally { myConnection.Close(); }}