首先是源数据是否支持事务,如果不支持可以使用MTS,启动事务在Connection中有方法可以取得事务管理器

解决方案 »

  1.   

    有没有人能告诉我OleDb是否支持事务,要怎样才能完成一个事务。
      

  2.   

    BeginTransaction,和COMMIT,ROLLBACK该怎么写呢,没有发现这些方法啊。 
      

  3.   

    SqlConnection sqlConnection = new SqlConnection("workstation id=WEIXIAOPING;packet size=4096;user id=sa;initial catalog=Northwind;persist security info=False");
       sqlConnection.Open();
       SqlTransaction  myTrans = sqlConnection.BeginTransaction();
       SqlCommand sqlInsertCommand = new SqlCommand();
       sqlInsertCommand.Connection = sqlConnection
       sqlInsertCommand.Transaction=myTrans;
       try{
           sqlInsertCommand.CommandText="insert into tbTree(Context,ParentID) values('北京',1)";
           sqlInsertCommand.ExecuteNonQuery();
           sqlInsertCommand.CommandText="insert into tbTree(Context,ParentID) values('上海',1)";
           sqlInsertCommand.ExecuteNonQuery();
           myTrans.Commit();
         }catch(Exception ex)
         {
          myTrans.Rollback();
         }
        finally
        {
         sqlConnection.Close();
        }
    这是sqlConnection 的一个例子,换成OleDbConnection
      

  4.   

    可以使用 COM+ 中的事务,使用 System.EnterpriseServices.ContextUtil 类。