Click here to Skip to main content
15,920,801 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
When i click save button on the form

it calls 3 methods
save_Purchase();
save_dtPurcaseProduct();
save_dtPurchaseProductExp();
these 3 methods save changes to 3 database tables

so the scenario is
3 tables or none must get the changes
Posted

1 solution

USE Transaction in your fron-end, and put the code that saves the data in to database within that transaction scope . It will meet your Requirement.

C#
bool isSuccess=false;//Global Variable
 using (TransactionScope transScope = new TransactionScope())
                 {
                          /*here goes stufs for insertion of data in database like */
                     
                         if (insertCommand1>0 && insertCommand2>0 && insertCommand3>0)
                          {
                             isSuccess = true;
                         }
                     }
                     transScope.Complete();
                     insertCommand1.Dispose();
                     insertCommand2.Dispose()
                     insertCommand3.Dispose()
                     DataBaseConnection.Dispose();
                     
                 }
             }
             catch (TransactionAbortedException ex)
             {
                 MessageBox.Show(ex.Message.ToString(), "Error");
             }
             catch (ApplicationException ex1)
             {
                 MessageBox.Show(ex1.Message.ToString(), "Error");
             }
             if (isSuccess == true)
             {
                 MessageBox.Show("Data Saved Successfully", "Success");
             }
         }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900