在.NET 2.0 中使用自定义事务操作
2008-03-11 10:14
323 查看
.net 2.0 framework 中新增了 System.Transactions 命名空间,其中提供的一系列接口和类使得在.net 2.0 中使用事务比起从前要方便了许多。有关在 .net 2.0 下操作数据库事务的文章已经有了很多,这里只提一下如何设计自定义事务操作。
相关实例代码:
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSelect_Click(object sender, EventArgs e)
{
GvBind();
}
private void GvBind()
{
this.GridView1.DataSource = DbHelperSQL.Query("SELECT * FROM Items");
this.GridView1.DataBind();
}
protected void btnAdd_Click(object sender, EventArgs e)
{
// 声明定义事务
using (TransactionScope ts = new TransactionScope())
{
try
{
// 事务方法体
Sub1();
Sub2();
// 提交事务并回滚
ts.Complete();
}
catch
{ }
}
this.GvBind();
}
private static void Sub2()
{
DbHelperSQL.ExecuteSql("INSERT INTO Items(Item) VALUES('aa')");
}
private static void Sub1()
{
DbHelperSQL.ExecuteSql("INSERT INTO Items(Item) VALUES(101)");
}
相关实例代码:
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSelect_Click(object sender, EventArgs e)
{
GvBind();
}
private void GvBind()
{
this.GridView1.DataSource = DbHelperSQL.Query("SELECT * FROM Items");
this.GridView1.DataBind();
}
protected void btnAdd_Click(object sender, EventArgs e)
{
// 声明定义事务
using (TransactionScope ts = new TransactionScope())
{
try
{
// 事务方法体
Sub1();
Sub2();
// 提交事务并回滚
ts.Complete();
}
catch
{ }
}
this.GvBind();
}
private static void Sub2()
{
DbHelperSQL.ExecuteSql("INSERT INTO Items(Item) VALUES('aa')");
}
private static void Sub1()
{
DbHelperSQL.ExecuteSql("INSERT INTO Items(Item) VALUES(101)");
}
相关文章推荐
- 在 .net 2.0 中使用自定义事务操作
- 在.NET2.0中使用自定义事务操作
- 在.NET2.0中使用自定义事务操作
- 使用.Net2.0的事务
- 使用.Net2.0的事务
- QListView使用自定义的拖放操作
- 在ASP.NET 2.0中操作数据之三十一:使用DataList来一行显示多条记录
- 在 .NET 中使用 Oracle 数据库事务
- 项目中使用的自定义数据访问类(复杂查询,复杂操作)
- 使用TransactionScope实现单数据库连接事务操作
- .NET 使用 MySql.Data.dll 动态库操作MySql的帮助类--MySqlHelper
- Flex Ari中操作SQLite中使用事务
- [翻译] Scott Mitchell 的ASP.NET 2.0数据操作教程之七:使用DropDownList过滤的主/从报表
- 粗略使用.NetCore2.0自带授权登陆Authorize
- [翻译] Scott Mitchell 的ASP.NET 2.0数据操作教程之十:使用 GridView 和DetailView实现的主/从报表
- 使用Visual Studio生成安装程序并设定连接字符串及其他自定义操作.
- 关于Quartz.net 2.0的使用说明
- .Net 2.0对文件传输协议(FTP)操作(上传,下载,新建,删除,FTP间传送文件等) 2
- 在 .NET 中使用 oracle 数据库 事务提交,事务保存点