How do I create a transaction?

gepabaro

New Member
How do I create a transaction? I am trying to update a rows in a database and the send an email. If the email fails I want to roll back the transaction. <BR><BR>Imports ????<BR><BR>Try <BR> ' start transaction ??<BR><BR> 'update database (I have the code for this)<BR><BR> 'Send email(I have the code for this)<BR><BR>Catch ex As Exception<BR> 'abort transaction<BR>Finally<BR> 'commit transaction<BR>End try<BR><BR>Try something like this<BR><BR>Dim objConnect as New ADOConnection(myConnectionString)<BR>Dim objCommand as New ADOCommand()<BR>Dim objTransaction as OleDBTransaction<BR><BR>Try<BR> objConnect.Open()<BR> objTransaction = objConnect.BeginTransaction()<BR><BR> objCommand.Connection = objConnect<BR> objCommand.CommandType = CommandType.Text<BR><BR> 'Attach the transaction to the command object<BR> objCommand.Transaction = objTransaction<BR><BR> '...Assign SQL to CommandText property and execute here ...<BR> ' and if all goes well then commit transaction<BR><BR> objTransaction.Commit()<BR><BR>Catch objError as Exception<BR><BR> 'If something booboos then roll it back<BR> objTransaction.Rollback()<BR><BR>End Try<BR>
 
Back
Top