Solved

Add transaction in this code

Posted on 2006-11-19
4
153 Views
Last Modified: 2010-04-23
How I can do for add a Transaction in this code?


           'Actualizo datos deposito salida
            Me.DepositosTableAdapter.FillByDepositoID(Me.DepositosDataSet.Depositos, Me.txtDepositoSalida.Text)
            Me.DepositosDataSet.Depositos.Rows(0).Item("Acidez") = AcidezSalFin
            DepositosTableAdapter.Update(Me.DepositosDataSet.Depositos)

            'Actualizo datos deposito entrada
            Me.DepositosTableAdapter.FillByDepositoID(Me.DepositosDataSet.Depositos, Me.txtDepositoEntrada.Text)
            Me.DepositosDataSet.Depositos.Rows(0).Item("litros") = LitrosEntFin
            DepositosTableAdapter.Update(Me.DepositosDataSet.Depositos)

            'Añado trasiego --------------------------------------------------------------
            Me.TrasiegosTableAdapter.Fill(Me.TrasiegosDataSet.Trasiegos)
            'Add a new row
            Dim tempRow As DataRow
            tempRow = TrasiegosDataSet.Tables("Trasiegos").NewRow()
            tempRow("TrasiegoID") = Me.TrasiegosDataSet.Trasiegos.Count + 1
            TrasiegosDataSet.Tables("Trasiegos").Rows.Add(tempRow)
            TrasiegosTableAdapter.Update(Me.TrasiegosDataSet.Trasiegos)
0
Comment
Question by:miguelmam
  • 2
4 Comments
 
LVL 10

Accepted Solution

by:
Kinger247 earned 500 total points
ID: 17974507
Hi miguelmam,

I've quickly put this together, this code won't work straight off, as you'll need to amend it for your use.
But you'll see that the transaction code is linked to your comman object.
This, if fails will trigger the catch and will roll back the first savepoint.

        Dim myConnection As New SqlClient.SqlConnection(My.Settings.DBConnection)
        Dim myCommand As New SqlClient.SqlCommand
        Dim myTran As SqlClient.SqlTransaction
        Dim DepositosTableAdapter As SqlClient.SqlDataAdapter
        Dim TrasiegosTableAdapter As SqlClient.SqlDataAdapter
        Dim DepositosDataSet As New DataSet
        Dim TrasiegosDataSet As New DataSet

        myTran = myConnection.BeginTransaction
        myCommand.Transaction = myTran

        Try
            myTran.Save("SavePoint")


            myCommand.CommandText = "?????"
            TrasiegosTableAdapter = New SqlClient.SqlDataAdapter(myCommand)
            DepositosTableAdapter.Fill(DepositosDataSet, txtDepositoSalida.Text)
            DepositosDataSet.Tables(0).Rows(0).Item("Acidez") = AcidezSalFin
            DepositosTableAdapter.Update(DepositosDataSet)

            myCommand.CommandText = "?????"
            TrasiegosTableAdapter = New SqlClient.SqlDataAdapter(myCommand)
            DepositosTableAdapter.Fill(DepositosDataSet, txtDepositoEntrada.Text)
            DepositosDataSet.Tables(0).Rows(0).Item("litros") = AcidezSalFin
            DepositosTableAdapter.Update(DepositosDataSet)

            myCommand.CommandText = "?????"
            TrasiegosTableAdapter = New SqlClient.SqlDataAdapter(myCommand)
            TrasiegosTableAdapter.Fill(TrasiegosDataSet)
            'Add a new row
            Dim tempRow As DataRow
            tempRow = TrasiegosDataSet.Tables("Trasiegos").NewRow()
            tempRow("TrasiegoID") = TrasiegosDataSet.Tables.Count + 1
            TrasiegosDataSet.Tables("Trasiegos").Rows.Add(tempRow)
            TrasiegosTableAdapter.Update(TrasiegosDataSet)


        Catch ex As Exception
            myTran.Rollback("SavePoint")

            MessageBox.Show(ex.Message, "Error")
        Finally
            myConnection.Close()
        End Try
0
 
LVL 10

Expert Comment

by:Kinger247
ID: 18015923
Hi miguelmam, did this work for you ?
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now