?
Solved

Add transaction in this code

Posted on 2006-11-19
4
Medium Priority
?
207 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 2000 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 does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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 is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

764 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