在methods参数中接收transaction-argument

时间:2016-06-23 10:30:54

标签: c# ms-access

如何在methods参数中接收事务作为参数?

    private void method_A(/*How to receive command-transaction here? */)
    {
    /* doing tons of db stuff.. */
    }

    protected void Insert_OnClick(object sender, EventArgs e)
    {
           //begin transaction
           var connection = WhatEverMyConnectionsIs();
           using (var transaction = connection.BeginTransaction())
           {

           try
           {
               var command = new OldDbCommand();
               command.Transaction = transaction;

               Method_A(command);

               Method_B(command);

               Method_C(command);

               transaction.Commit();
           }
           catch(Exception ex)
           {
               //if there was an exception rollback.
               transaction.Rollback();
           }
         }    

     }

此外,一旦我将事务传递给一个方法参数,在那里我得到了一些db read / insert / update语法,我是否还必须在方法中做任何特定的事情?我之前从未使用过交易。

0 个答案:

没有答案