chopperfield
chopperfield

Reputation: 567

prevent previous insert when failed to insert

I have multiple functions to save (insert) to database.

What I want is, if there is 1 function which gets an error saving (inserting) to the database, any previous saves (inserts) are not committed.

For example:

//button click event
 Try
    insert_a()
    insert_b() 
    insert_c()
    insert_d()
 Catch
    MsgBox("Failed to insertaaaaa !")
 End Try
//

Let's say the error I got was in insert_c, but insert_a and insert_b already ran and saved (inserted) to the database.

How do I not commit the save to database for c and a and also stop running insert_d function?

Upvotes: 1

Views: 50

Answers (1)

anveshtummala
anveshtummala

Reputation: 432

You need to start transaction and rollback it when you catch the error.

Upvotes: 1

Related Questions