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
查看全文
相关阅读:
C语言的存储类别和动态内存分配
C语言中复杂的声明
C语言中typedef的解释_2
C语言中类型限定符
C语言文件I/O和标准I/O函数
C语言中存储类别、链接与内存管理
C++中static与const成员
C++多态、虚函数、纯虚函数、抽象类
sizeof结构体
杂类
原文地址:https://www.cnblogs.com/adylee/p/3473634.html
最新文章
【ZZ】Python入门神图
学习笔记之设计模式
【ZZ】一张图清晰追溯数据库的发展历程(1962-2016年)
【ZZ】Java : 一个帝国的诞生 & 假如时光能够倒流, 我会这么学习Java
面试总结之查找算法
面试总结之数据结构(Data Structure)
LeetCode 341. Flatten Nested List Iterator
学习笔记之如果有人问你数据库的原理,叫他看这篇文章
腾讯//二叉树中的最大路径和
腾讯//二叉树中的最大路径和
热门文章
腾讯//二叉树的最大深度
腾讯//二叉树的最大深度
腾讯//二叉搜索树中第K小的元素
腾讯//二叉搜索树中第K小的元素
腾讯// 数组中的第K个最大元素
腾讯// 数组中的第K个最大元素
腾讯//搜索旋转排序数组
腾讯//搜索旋转排序数组
C++_了解虚函数的概念
C语言抽象数据类型ADT
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