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

ASP.NET
妙用Cache检验用户是否重复登陆
ASP.NET 2.0–善用DataSourceMode属性
在ASP.NET AJAX中别使用mode="Legacy"
探讨ASP.NET 2.0的Web控件改进之概述
asp.net创建文件夹的IO类的问题
asp.net 实现购物车详细代码
ASP.NET2.0+SQL Server2005构建多层应用
用ICallbackEventHandler实现客户端与服务器端异步
ASP.NET页面的重定向
抢先试用ASP.NET 2.0中的新型安全控件
ASP.NET中Cookie编程的基础知识
Asp.net导航控件真的值得用吗?
ASP.NET中上传文件到数据库
cs及前身asp.net forums的调试
ASP.NET2.0 遍历文件夹下所有图片
用ASP.NET创建自定义文本框
ASP.NET中设计带事件定制控件
ASP.NET+ORACLE添加记录让ID自动增量
C#+ASP.NET开发基于Web的RSS阅读器
ASP.NET2.0导航功能之配置会员和角色

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 125 ::
收藏到网摘: 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(); }}