How do I create a transaction?

Results 1 to 2 of 2

Thread: How do I create a transaction?

  1. #1
    Join Date
    Dec 1969

    Default How do I create a transaction?

    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> &#039; start transaction ??<BR><BR> &#039;update database (I have the code for this)<BR><BR> &#039;Send email(I have the code for this)<BR><BR>Catch ex As Exception<BR> &#039;abort transaction<BR>Finally<BR> &#039;commit transaction<BR>End try<BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default RE: How do I create a transaction?

    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> &#039;Attach the transaction to the command object<BR> objCommand.Transaction = objTransaction<BR><BR> &#039;...Assign SQL to CommandText property and execute here ...<BR> &#039; and if all goes well then commit transaction<BR><BR> objTransaction.Commit()<BR><BR>Catch objError as Exception<BR><BR> &#039;If something booboos then roll it back<BR> objTransaction.Rollback()<BR><BR>End Try<BR>

Posting Permissions

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