Solved

Add transaction in this code

Posted on 2006-11-19
4
189 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.

756 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