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

ASP.NET
用 Asp.Net 建立一个在线 RSS 新闻聚合器的方法
关于前台调用后台事件__doPostBack函数
Bin 和 App_Code 文件夹介绍
.NET 2.0 的压缩功能代码
解决Visual Studio 2005 无法显示设计视图的方法
asp.net(c#)两种随机数的算法,可用抽考题
asp.net下url传递中文的解决方案
XmlReader 读取器读取内存流 MemoryStream 的注意事项
asp.net下创建、查询、修改带名称空间的 XML 文件的例子
使用.NET存储XML数据的方法
XslTransform.Transform将结果输出到字符串里的方法
安装 VS2005 SP1 有关问题的解决办法
asp.net下中文验证码,免费开源代码
自定义应用程序配置文件(app.config)
asp.net下使用DIME协议上传文件
动态改变ASP.net页面标题和动态指定页面样式表的方法
WEB上调用HttpWebRequest奇怪问题的解决方法
HTTP协议下用Web Service上传大文件的解决方案
asp.net下Response.ContentType类型汇总
ASP.NET User Control使用技巧一则

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


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