SqlDataAdapter处理事务,请问谁做过

cnn3 2006-05-14 12:19:31
SqlDataAdapter怎么处理事务呢,没找到相关代码,哪位朋友能提供下
...全文
256 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Yanglintao 2006-10-22
  • 打赏
  • 举报
回复
我刚刚在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的操作都无效。
dgrwang 2006-08-03
  • 打赏
  • 举报
回复
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();
}
cnn3 2006-05-14
  • 打赏
  • 举报
回复
tt
marvelstack 2006-05-14
  • 打赏
  • 举报
回复
可以试一下这里的方法
http://blog.csdn.net/zhzuo/archive/2004/08/06/67037.aspx
keyanshang 2006-05-14
  • 打赏
  • 举报
回复

this._DBAdpt-------------SqlDataAdapter
this._DBConn-------------SqlDataConnection


//事务开始
this._DBAdpt.InsertCommand.Transaction = this._DBConn.BeginTransaction();
//事务回滚
this._DBAdpt.InsertCommand.Transaction.Rollback();
//事务提交
this._DBAdpt.InsertCommand.Transaction.Commit();

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧