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
查看全文
相关阅读:
LeetCode 79. 单词搜索(Word Search)
LeetCode 39. 组合总和(Combination Sum)
LeetCode 34. 搜索范围(search for a range)
LeetCode 300. 最长上升子序列(Longest Increasing Subsequence)
一段程序的分析——C++析构器,何时析构
C++ 字符串, 数字 相互转化
MFC 如何为控件关联变量
上位机驱动开发经验之修改3个“附加”
MFC Edit控件的使用~~
thinkphp中AJAX返回ajaxReturn()方法分析
原文地址:https://www.cnblogs.com/adylee/p/3473634.html
最新文章
usb3.0 monitor is already started
iml文件
greenDao 介绍
eclipse git
读万卷书,行万里路。
Request获取信息总结
return view详解
Map工具系列-01-Map代码生成工具说明
VS2012连接到osc@git
Angulajs系列-01-入门
热门文章
Microsoft Hololens 入门系列-01-开篇
网站的监控指南
Metro-UI系统-2-color和icon
设计模式系列-02-创建模式-简单工厂
LeetCode 19. 删除链表的倒数第N个节点(Remove Nth Node From End Of List)
LeetCode 16. 最接近的三数之和(3Sum Closest)
LeetCode 120. 三角形最小路径和(Triangle)
LeetCode 43. 字符串相乘(Multiply Strings) 大数乘法
LeetCode 11. 盛最多水的容器(Container With Most Water)
LeetCode 55. 跳跃游戏(Jump Game)
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