Hello Swami,
When you are using a CommandBuilder and you want to use transactions, you must associate the transaction with the
SelectCommand of the DataAdapter before calling Update. Then, the CommandBuilder will automatically enlist all
generated commands in the transaction when you call Update.
For an example:
data_adapterSelectcommand.Transaction = trans;
data_adapter.InsertCommand.Transaction = trans;
data_adapter.UpdateCommand.Transaction = trans;
data_adapter.DeleteCommand.Transaction = trans;
Hope it helps.
Best regards,
Yanhong Huang
Microsoft Online Partner Support
Get Secure! -
www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
!Content-Class: urn:content-classes:message
!From: "Swami Muthuvelu" <sw***@mclsystems.com>
!Sender: "Swami Muthuvelu" <sw***@mclsystems.com>
!Subject: SqlTransaction
!Date: Mon, 28 Jul 2003 16:51:22 -0700
!Lines: 38
!Message-ID: <04****************************@phx.gbl>
!MIME-Version: 1.0
!Content-Type: text/plain;
! charset="iso-8859-1"
!Content-Transfer-Encoding: 7bit
!X-Newsreader: Microsoft CDO for Windows 2000
!X-MIMEOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
!Thread-Index: AcNVYyXY+PcCw/X4Qo2zrO1QD6xvrA==
!Newsgroups: microsoft.public.dotnet.general
!Path: cpmsftngxa06.phx.gbl
!Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:102645
!NNTP-Posting-Host: TK2MSFTNGXA12 10.40.1.164
!X-Tomcat-NG: microsoft.public.dotnet.general
!
!Hi,
!I using command builder to generate my insert, update and
!delete statements..something like,
!
!data_adapter = New SqlClient.SqlDataAdapter(SQL,
!ActiveConnection)
!
!command_builder = New SqlClient.SqlCommandBuilder
!(data_adapter)
!
!After filling a data grid and making changes to the data,
!I want to call the adapter.Update method in a database
!transaction, so that I can rollback the transaction, if
!the update fails..
!This is my code, for that..
!***************************************
!Dim trans As SqlClient.SqlTransaction
!trans = adp.SelectCommand.Connection.BeginTransaction
!adp.Update(ds)
!***************
!In the adp.Update(ds) line, I get the exception,
!"Execute requires the command to have a transaction object
!when the connection assigned to the command is in a
!pending local transaction. The Transaction property of
!the command has not been initialized."
!
!What am I doing wrong..?
!Please help with a code snippet.
!
!Regards,
!Swami
!
!
!
!
!
!
!
!