Wrox Programmer Forums
|
BOOK: Beginning ASP.NET 1.1
This is the forum to discuss the Wrox book Beginning ASP.NET 1.1 with Visual C#.NET 2003 by Chris Ullman, John Kauffman, Chris Hart, Dave Sussman, Daniel Maharry; ISBN: 9780764557088
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 9th, 2004, 11:24 AM
Authorized User
 
Join Date: Jul 2003
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default ADO.NET transaction processing

Hi

I want to be able to prompt a user to decide whether they want to commit or rollback their database changes but don't know how.

I found some code that shows the logic of transaction but can't see a way of making it handle yes/no prompt.

Code is below:

<script language="vb" runat="server">
Sub Page_Load()
     Dim myConnection As OdbcConnection = New OdbcConnection ("dsn=books.udd;uid=;pwd=;")
     myConnection.Open()
     con_open.text="Connection Open successfully.<br />"

     Dim mystring As String = "Select * from customer where custcode = 'C001'"
     Dim cmd As OdbcCommand = New OdbcCommand(mystring, myConnection)

' Display original data in a DataGrid

     table_orig.text="Display original data record.<br />"
     dgEmps.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection)
     dgEmps.DataBind()

' Start a local transaction.

   myConnection.Open()
   Dim myTrans As OdbcTransaction = myConnection.BeginTransaction()

' Enlist the command in the current transaction.

   Dim myCommand As OdbcCommand = myConnection.CreateCommand()
   myCommand.Transaction = myTrans

   Try
      myCommand.CommandText = "update customer set cust_region = 'NORD' where custcode = 'C001'"
         trans_start.text="Transaction started successfully.<br />"
     myCommand.ExecuteNonQuery()
         trans_query.text="Transaction UPDATE query issued.<br />"

     myTrans.Commit()

     Console.WriteLine("Record has been written to database.")
         trans_commit.text="Transaction UPDATE query completed successfully.<br />"
   Catch e As Exception
   Try
         myTrans.Rollback()
         trans_rollback.text="Transaction UPDATE query rollbacked.<br />"
   Catch ex As OdbcException
         If Not myTrans.Connection Is Nothing Then
             Console.WriteLine("An exception of type " & ex.GetType().ToString() & _
                         " was encountered while attempting to roll back the transaction.")
         End If
  End Try

  Console.WriteLine("An exception of type " & e.GetType().ToString() & _
                    "was encountered while inserting the data.")
  Console.WriteLine("Neither record was written to database.")

Finally
     table_change.text="Display changed data record.<br />"

' Display changed record in a DataGrid

     dgEmps1.DataSource = cmd.ExecuteReader(CommandBehavior.CloseConnection)
     dgEmps1.DataBind()

     myConnection.Close()

     con_close.text="Connection Closed successfully.<br />"
End Try

end Sub
</script>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between ADO and ADO.NET rakeshclose2u ADO.NET 2 April 23rd, 2007 03:57 AM
How to interrupt processing the LOOP in ASP.NET Dmitriy ASP.NET 2.0 Professional 2 November 29th, 2006 12:19 PM
How to interrupt processing the LOOP in ASP.NET Dmitriy General .NET 2 January 13th, 2006 08:43 AM
How to interrupt processing the LOOP in ASP.NET Dmitriy Classic ASP Professional 0 December 13th, 2005 08:19 AM
Transaction in ADO.NET gunandhini ADO.NET 5 April 10th, 2005 03:46 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.