zoukankan
html css js c++ java
SqlDataAdapter怎么处理事务呢
SqlDataAdapter怎么处理事务呢,没找到相关代码,哪位朋友能提供下
解决方案 »
this._DBAdpt-------------SqlDataAdapter
this._DBConn-------------SqlDataConnection
//事务开始
this._DBAdpt.InsertCommand.Transaction = this._DBConn.BeginTransaction();
//事务回滚
this._DBAdpt.InsertCommand.Transaction.Rollback();
//事务提交
this._DBAdpt.InsertCommand.Transaction.Commit();
可以试一下这里的方法
http://blog.csdn.net/zhzuo/archive/2004/08/06/67037.aspx
SqlConnection sqlConnection = new SqlConnection();
...初始化连接
// 开启事务
SqlTransaction sqlTransaction = sqlConnection.BeginTransaction();
// 将事务应用于Command
SqlCommand sqlCommand = new SqlCommand();
sqlCommand.Connection = sqlConnection;
sqlCommand.Transaction = sqlTransaction;try
{
// 利用sqlcommand进行数据操作
...
// 成功提交
sqlTransaction.Commit();
}
catch(Exception ex)
{
// 出错回滚
sqlTransaction.Rollback();
}
我刚刚在vs2005c#上做成功,是这样的:
using (TransactionScope transScope = new TransactionScope())
{
DS表TableAdapters.表TableAdapter daB=new 名空间.DS表TableAdapters.表TableAdapter();
try
{
daB.Insert("a", "b");
daB.Insert("a", "c");
........
// The Complete method commits the transaction.
transScope.Complete();
}
catch
{
}
}
只要程序运行不到tranScope.Complete();所有daB的操作都无效。
http://www.debugease.com/csharp/1706270.html
查看全文
相关阅读:
VWG中设置URL编码的方法
wordwrap breakword
iis6下配置支持.net4.0&发布网站[转]
MySQL修复打不开的视图定义
DHTML CSS+JavaScript设计网页链接提示ToolTips
C# 计算文件的MD5值
.Net+IIS环境经常出现的问题及排障[转]
我的WCF之旅(1):创建一个简单的WCF程序[转]
C#嵌套类的使用方法及特性[转]
设置<table>的固定长度
原文地址:https://www.cnblogs.com/adylee/p/3473634.html
最新文章
TOPCODER>Practice Room>SRAM 144 DIV 1 (550)
UNIXLINUX编程实践教程>第三章>实例代码注解>ls2
TOPCODER>使用方法>(2)如何登陆客户端
TimeTool>文档>需求书
UNIXLINUX编程实践教程>第三章>实例代码注解>ls1
UNIXLINUX C语言编程>异常收集>undefined reference to `main'
杂文>一个编程竞技游戏的设想
UNIXLINUX C语言编程>实验室>多次打开文件实验
TimeTool>文档>需求分析
TOPCODER>Practice Room>SRAM 144 DIV 1 (300)
热门文章
Linux Shell高级技巧(一)
Linux Shell高级技巧(三)
Linux Shell常用技巧(九)
Linux Shell高级技巧(二)
Linux Shell常用技巧(目录)
Linux Shell高级技巧(四)
Linux Shell高级技巧(五)
Linux Shell常用技巧(十二)
Linux Shell常用技巧(十一)
Linux Shell常用技巧(十)
Copyright © 2011-2022 走看看
this._DBAdpt-------------SqlDataAdapter
this._DBConn-------------SqlDataConnection
//事务开始
this._DBAdpt.InsertCommand.Transaction = this._DBConn.BeginTransaction();
//事务回滚
this._DBAdpt.InsertCommand.Transaction.Rollback();
//事务提交
this._DBAdpt.InsertCommand.Transaction.Commit();
http://blog.csdn.net/zhzuo/archive/2004/08/06/67037.aspx
...初始化连接
// 开启事务
SqlTransaction sqlTransaction = sqlConnection.BeginTransaction();
// 将事务应用于Command
SqlCommand sqlCommand = new SqlCommand();
sqlCommand.Connection = sqlConnection;
sqlCommand.Transaction = sqlTransaction;try
{
// 利用sqlcommand进行数据操作
...
// 成功提交
sqlTransaction.Commit();
}
catch(Exception ex)
{
// 出错回滚
sqlTransaction.Rollback();
}
using (TransactionScope transScope = new TransactionScope())
{
DS表TableAdapters.表TableAdapter daB=new 名空间.DS表TableAdapters.表TableAdapter();
try
{
daB.Insert("a", "b");
daB.Insert("a", "c");
........
// The Complete method commits the transaction.
transScope.Complete();
}
catch
{
}
}
只要程序运行不到tranScope.Complete();所有daB的操作都无效。
http://www.debugease.com/csharp/1706270.html