Results 1 to 2 of 2

Thread: Multiple Transaction

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2010
    Posts
    6

    Multiple Transaction

    I using two tables H1, D1 where FieldID is primary key for H1.

    Now i am trying to insert table H details. on excution of line 5 i will end the program. now table H details should rollback.

    Any Idea pls.

    Private sub cmbSumit()
    conn.BeginTrans
    conn.BeginTrans
    conn.Excute "update H1 set Fname = 'City1' where FieldID=7"
    Conn.CommitTrans
    Conn.Excute "update D1 set name = 'Ram' where FieldID=7"
    Conn.CommitTrans

    End Sub

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Multiple Transaction

    The point of using transaction is to be able to execute multiple statements (insert, delete, update) and then commit changes or roll everything back in case of error.
    You may use transaction to update single table but in your case I don't much point in it since it appears that both tables relate on ID (id=7).
    So, what I would do is to use single transaction to update both tables:
    Code:
    Option Explicit
    
    Private Sub cmbSumit()
    On Error GoTo ErrHandler
    
        Conn.BeginTrans
        Conn.Excute "update H1 set Fname = 'City1' where FieldID=7"
        Conn.Excute "update D1 set name = 'Ram' where FieldID=7"
        Conn.CommitTrans
        
        Exit Sub
        
    ErrHandler:
    
        MsgBox Err.Description
        Conn.RollbackTrans
        Err.Clear
    
    End Sub

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width