Solved

Add transaction in this code

Posted on 2006-11-19
4
201 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 …
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

726 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