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 February 6th, 2008, 05:42 PM
Registered User
 
Join Date: Feb 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Best way to bind commands to transactions

Is this a correct way of assigning commands to a transaction in ado.net?

Connection.Open()
Command.Transaction = Connection.BeginTransaction()
Try
 Command.CommandText = "DELETE FROM table1 WHERE ID = @id "
 Command.Parameters.Add("@id", sID)
 Command.ExecuteNonQuery()

 Command.CommandText = "INSERT INTO table2( blah) VALUES( @blah )"
 Command.Parameters.Add("@blah", 111).DbType = DbType.Int64
 Command.ExecuteNonQuery()

 Command.Transaction.Commit()

Catch ex As Exception
 Command.Transaction.Rollback()
 Throw New Exception( ex.Message, ex)
Finally
 Command.Parameters.Clear()
 Connection.Close()
 Connection.Dispose()
 Command.Dispose()
End Try

Or do i need to create two different command instances one for each DML string and then seperately assign them to the Transaction?

Thanks







Similar Threads
Thread Thread Starter Forum Replies Last Post
Transactions???? CRONER BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 February 4th, 2009 04:43 PM
Asynchronous Transactions jroxit Other Programming Languages 0 July 29th, 2008 11:12 AM
ABOUT AT COMMANDS bobwith5 Visual Basic 2005 Basics 1 October 31st, 2007 02:25 PM
transactions.... Johnslg BOOK: Expert SQL Server 2005 Integration Services ISBN: 978-0-470-13411-5 0 August 20th, 2007 08:51 AM
Chapter 3 - Transactions PedroPN BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 3 December 1st, 2006 07:42 PM





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