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
查看全文
相关阅读:
为什么不使用CSS expression?
关于ol有序列表的小事儿...
绝对定位的元素在IE6下莫名丢失解决办法
C#操作XML
.NET MSChart应用的一个简单例子 (转)
微软图表控件MsChart使用初探(转)
使用OleDbParameter来写Access的更新没反应的解决办法
获取真实IP
XML操作类转
Model与XML互相转换
原文地址:https://www.cnblogs.com/adylee/p/3473634.html
最新文章
PostBackUrl与Response.Redirect()区别
Oracle学习笔记(包基本结构)
oracle 函数捕获错误模板
oracle 触发器模板
sql 内连接 左连接 右连接用法详解
Oracle学习笔记(Max函数好用)
Jquery左右无缝图片滚动插件(原创)
asp.net跨页面传值收集
设计模式备忘录(转)
技术文章待出,心情随笔先行
热门文章
开发者如何提升和推销自己(转)
动态规划专题[1]: 简单线性DP
DM数据库迁移工具使用
达梦数据库下载安装及简单使用
怎么得到新浪每条微博详细页地址?
VS.NET 学习方法论 ——我的VS.NET学习之旅
英特尔® Performance Counter Monitor(PCM)——测量 CPU 利用率的更好方法
.net: 怎么 让VS 识别自定义的文件类型?
求粉 ~~~~~~http://weibo.com/51qqhe
【整理】详说JPG,GIF及PNG各类型的图片格式
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