There's several ways to approach this. You could use COM+ (Enterprise
Services) and require transactions, but the simplest is to use the
SqlTransaction object:
Here's a brief excerpt. It assumes you are using SQL Server and
SqlDataAdapters .
// Create a SqlTranaction
SqlTransaction trans;
trans = myConnection.Be ginTransaction( );
try
{
// Assign the correct adapters and Commands to the transaction;
// These can be Update, Insert, or Delete Commands;
dataAdapter1.Up dateCommand.Tra nsaction = trans;
dataAdapter2.In sertCommand.Tra nsaction = trans;
dataAdapter3.De leteCommand.Tra nsaction = trans;
// Call the update methods for each adapter involved in the transaction;
dataAdapter1.Up date(dataset);
dataAdapter2.Up date(dataset);
dataAdapter3.Up date(dataset);
// Commit the transaction;
trans.Commit();
}
catch(Exception e)
{
//If an exception occurs, then we need to rollback the transaction;
trans.Rollback( );
}
Hope this helps.
Dave
"viktor9990 " <vi********@dis cussions.micros oft.com> wrote in message
news:C7******** *************** ***********@mic rosoft.com...
I'm inserting info in database when clicking a button. Some procedure are
called. I want to do that with a transaction (when clicking on the button
and within its procedure) so that everything will be
inserted or nothing. How to do that? Thanks
Private Sub btnRegister_Cli ck(ByVal sender As System.Object, ByVal e As
System.EventArg s)
addExtPartyList ToDB()
AddReminderDB()
addCostSplitDB( )
AddMoneyDB()
AddinfoDB()
AddmemberDB()
end sub