当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > 数据库事务处理的另外一种方法

ASP.NET
自定义控件(支持模板)
自定义控件(模板+数据绑定)
自定义控件(可以动态加载用户控件)
在代码隐藏中遍历当前页的所有控件
关于C#调用Office Web Components绘图的问题
利用Visual C#打造一个平滑的进度条
[VB] 防止程序运行多个实例
Visual Studio.Net 快捷键表
WinForm中ToolBar与TabControl的一些事件写法(C#)
【翻译】Managed DirectX(第六章)
利用.NET语言开发自己的脚本语言(一)
自动改变CheckBoxList选择项目的背景颜色
vb.net中windows服务的创建
BASE64编码规则及C#实现
.net中判断该应用程序是否已经启动,防止重复启动
XML Web Service 数据交换
开发花絮:一个DataList的ItemCommand事件意外
Snake.Net中的ORM(二)
ASP操作XML数据小结
可用来显示空值的时间选择控件4

ASP.NET 中的 数据库事务处理的另外一种方法


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

添加引用System.EnterpriseServices.dll using System.EnterpriseServices; 随便建立一个按钮,在按钮中进行如下操作: try { work1(); work2(); ContextUtil.SetComplete(); } catch(System.Exception except) { ContextUtil.SetAbort(); Response.Write(except.Message); } 然后在页面中添加2个操作,模拟一下在逻辑层调用不同类中的操作的情况 private void work1() { SqlConnection conn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["conn"]); SqlCommand cmd1=new SqlCommand("Insert Into trantest (id,test)values(1,'test')",conn); conn.Open(); cmd1.ExecuteNonQuery(); conn.Close(); } private void work2() { SqlConnection conn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["conn"]); SqlCommand cmd2=new SqlCommand("Insert Into trantest (id,test)values(2,'test')",conn); conn.Open(); cmd2.ExecuteNonQuery(); conn.Close(); }