Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 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 29th, 2004, 08:08 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default DataAdapter & transation

Hi there:
I have 4 DataAdapter to be apdated!
how can I meke a trasation for there 4 Adapter?!

Code:
Adapter1.Update(dsDabir1);
Adapter2.Update(dsDabir1);
Adapter3.Update(dsDabir1);
Adapter4.Update(dsDabir1);
Tnx in advance.

Always:),
Hovik Melkomian.
__________________
Always,
Hovik Melkomian.
 
Old March 3rd, 2004, 05:05 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

There is a SQLTransaction object that you can use. Using the connection object, you can establish a connection by:

SQLTransaction objTrans = objConnection.BeginTransaction(<Trans params>)

Then passing the transaction to each command object being used.

objCommand.Transaction = objTrans

or in your case

Adapter1.InsertCommand.Transaction = objTrans
Adapter1.UpdateCommand.Transaction = objTrans
Adapter1.DeleteCommand.Transaction = objTrans
...

Then you commit or rollback the transaction upon success/failure.

Brian
 
Old March 4th, 2004, 01:22 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

Yes I know about
Code:
objConnection.BeginTransaction
but it needs open Connection, but im using SqlAdapter & it handle its connection itself, thats why I asked friends:).

Now after creating objTrans like:
Code:
SQLTransaction objTrans = objConnection.BeginTransaction();
should I set this for all my Adapter Commands?!? How should I use it, Can u give a short sample for my codes, I'll be thankfull.

Always:),
Hovik Melkomian.
 
Old March 4th, 2004, 04:24 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

I think you said before on another thread that it is "bad practice" to use an explicit connection in combination with a SqlDataAdapter. I don't believe that it is true, and consequently, I don't agree with it.

The Adapter is capable of making sure it has a valid connection; however, there is nothing wrong with creating an explicit connection that you use for one or more dataadapters.

If you take a look here (constructor for an Adapter) you'll see that you can pass in a connection object that is already open. Only you are responsible for closing it again.

So, something like this is perfectly legal and "good practice"

Conn.Open()
// Do whatever you need to do with the connection
// Start a transaction, create and use adapters, whatever
// Continue doing that
Conn.Close()

So, even if the Adapter can handle the connection itself, you can also feed it an existing and open connection.

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
How many DataAdapter in a Form melvik ADO.NET 5 November 2nd, 2008 03:14 AM
update dataadapter karenai Visual Basic 2005 Basics 0 February 9th, 2008 10:46 PM
Dataadapter with parameter kau_shuk VS.NET 2002/2003 0 January 4th, 2007 02:43 AM
dataadapter --- dataset thas123 ASP.NET 2.0 Basics 0 December 13th, 2006 08:58 AM
Linux & KDE & C++ & QT & MYSQL & Kdevelop Munnnki Linux 0 January 2nd, 2005 05:41 PM





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