如题,谢谢。

解决方案 »

  1.   

    OracleConnection tempCnn = null;
    OracleTransaction tempTrans = null;
    OracleCommand tempcmd = null;
    try
    {
        //事务的连接
        tempCnn = new OracleConnection(ConnString);
        tempCnn.Open();
        tempcmd = new OracleCommand();
        tempTrans = tempCnn.BeginTransaction();
        tempcmd.Connection = tempCnn;
        tempcmd.Transaction = tempTrans;
        tempcmd.CommandText = "insert into ...";
        tempcmd.ExecuteNonQuery();
        tempTrans.Commit();
    }
    catch ( Exception ex)
    {
        if ( tempTrans != null )//回滚
            tempTrans.Rollback();
        throw ex;
    }
      

  2.   

    使用事务!
     Dim transaction As SqlTransaction        Try
                cnn.Open()
                transaction = cnn.BeginTransaction
                cmdStudent.Transaction = transaction
                transaction.Commit()          Catch ex As Exception
                transaction.Rollback()
                MessageBox.Show(ex.Message) ‘注意这里,要先回滚,然后报错。防止回滚被中断。
            Finally
                cnn.Close()
            End Try