Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET 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 10th, 2004, 07:51 AM
Authorized User
 
Join Date: Jul 2003
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default ADO.NET and Transactions

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 developed a VB sample on Windows that generated a MsgBox but that isn't an option for my web based code).

I found some code that shows the logic of transaction but can't see a way of making it handle yes/no prompt e.g. the prompt would offer yes/no option and then do something along the lines of if VbYes then do TransCommit etc etc).

My ASP.NET 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>
 
Old June 10th, 2004, 11:22 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hello,

Use two link buttons for yes/no. You can't use client-side javascript to prompt the user for this change. Then when the yes link button is clicked, commit the transaction, otherwise, rollback.

Brian





Similar Threads
Thread Thread Starter Forum Replies Last Post
Professional Visual Basic .NET Transactions kunalmandalia All Other Wrox Books 4 September 13th, 2009 08:32 PM
Difference between ADO and ADO.NET rakeshclose2u ADO.NET 2 April 23rd, 2007 03:57 AM
ADO AND ADO.NET royalsurej ADO.NET 1 November 8th, 2004 08:28 AM
Oracle transactions with ADO.net HelenR ADO.NET 0 July 5th, 2004 03:43 AM
need code of PROFESSIONAL VB.NET Transactions Zhongyanjun Wrox Book Feedback 1 October 16th, 2003 08:45 AM





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