asp.net调用事务

 public  int ExcuteCommand(string sql)
    {
        int result = -1;
        OleDbConnection myconn = getcon();
        OleDbTransaction trans = myconn.BeginTransaction(IsolationLevel.ReadCommitted);
        try
        {
            OleDbCommand cmd = new OleDbCommand(sql, myconn);
            cmd.Transaction = trans;
            trans.Commit();
            result = cmd.ExecuteNonQuery();
        }
        catch (Exception ex)
        {
            trans.Rollback();
            throw (ex);
        }
        finally
        {
            myconn.Dispose();
            myconn.Close();
        }
        return result;
    }

posted @ 2011-08-25 14:45  放哨De老鼠  阅读(355)  评论(0)    收藏  举报