2014-12-31 7 views
0

master_gid을 참조하여 하나의 마스터 테이블과 세부 테이블을 가지고 있는데, 마스터 테이블에 요약을 삽입하고 세부 테이블에 세부 정보를 삽입해야합니다. 모든 것이 잘 작동합니다. 시나리오 다음입니다 :데이터베이스에서 마지막으로 갱신을 취소합니다.

  1. 삽입 마스터 테이블
  2. 설명 테이블 삽입 마스터

모든 일 작업에서 삭제 참조 필드를 실패 할 경우 마스터 테이블 삽입 성공은 자세한 테이블

  • 를 삽입하는 경우 이번에는 괜찮아. 제가 동일한 시나리오 있지만 상세한 표 삽입 실패의 경우에이 문제에 직면 다음그 갱신의 경우

    . detail_table 삽입이 실패 할 경우 undo (쿼리 사용)에서 마스터 테이블의 마지막 업데이트를 어떻게 수행 할 수 있습니까? 여기 mysql

  • +0

    하위 끝이 ado.net'은 당신은'Transaction'를 사용할 수있는'사용하는 경우 명령 클래스의. –

    +0

    업데이트보기 :'Imports System.Data.Odbc'를 사용 중입니다. –

    답변

    0

    에 연결하기위한 Imports System.Data.Odbc을 사용하고하는 것은 MSDN에서 예 약 using transaction

    Public Sub ExecuteTransaction(ByVal connectionString As String) 
    
    Using connection As New OdbcConnection(connectionString) 
        Dim command As New OdbcCommand() 
        Dim transaction As OdbcTransaction 
    
        ' Set the Connection to the new OdbcConnection. 
        command.Connection = connection 
    
        ' Open the connection and execute the transaction. 
        Try 
         connection.Open() 
    
         ' Start a local transaction. 
         transaction = connection.BeginTransaction() 
    
         ' Assign transaction object for a pending local transaction. 
         command.Connection = connection 
         command.Transaction = transaction 
    
         ' Execute the commands. 
         command.CommandText = _ 
          "Insert into Region (RegionID, RegionDescription) VALUES (100, 'Description')" 
         command.ExecuteNonQuery() 
         command.CommandText = _ 
          "Insert into Region (RegionID, RegionDescription) VALUES (101, 'Description')" 
         command.ExecuteNonQuery() 
    
         ' Commit the transaction. 
         transaction.Commit() 
         Console.WriteLine("Both records are written to database.") 
    
        Catch ex As Exception 
         Console.WriteLine(ex.Message) 
         ' Try to rollback the transaction 
         Try 
          transaction.Rollback() 
    
         Catch 
          ' Do nothing here; transaction is not active. 
         End Try 
        End Try 
        ' The connection is automatically closed when the 
        ' code exits the Using block. 
    End Using 
    

    관련 문제