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
查看全文
相关阅读:
JavaScript Patterns and Good Parts
[Buzz Today]2012.05.015
The first glance at Python
The first glance at JavaScript
[Buzz Today]2012.05.06
vs.net2008 下 带完善后台管理的flash+js 轮显广告
Vs.net2008 下 Ajaxpro 使用
允许asp上传大文件的设置
使用AutocompleteExtender无效或者没反应,输入啥都在webservice里面跟踪不到
C#精髓 GridView 72般绝技
原文地址:https://www.cnblogs.com/adylee/p/3473634.html
最新文章
第十章 刚体平面运动 1
第八章 刚体基本运动
第十二章 动量定理和动量矩定理
UG OPEN API编程基础 7用户自定义对象
第四章 平面力系 1
§3 数量乘矢量
3§6空间两直线的相关位置
第2章 曲面与空间曲线的方程 §1 曲面的方程
第三篇 动力学引言 第十一章 质点动力学基本方程
§8 两矢量的矢量积
热门文章
第十章 刚体平面运动 2
§7 两矢量的数性积
§9 三矢量的混合积
第一章 矢量与坐标 §1 矢量的基本概念
OneNote比较有用的快捷键
JavaScript Advanced
[Buzz Today]2012.05.10
多视角看编程语言趋势
Node.js与Tornado,两个无阻塞的WebServer
The first glance at Scala
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