Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Add transaction in this code

Posted on 2006-11-19
4
Medium Priority
?
212 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

636 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