Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9151661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:51:24+00:00 2026-06-17T11:51:24+00:00

below is the code i am using for MySqlTransaction and it is running perfectly….

  • 0

below is the code i am using for MySqlTransaction and it is running perfectly….
but problem is as i am using single instance of mysqlcommand i have to use unique PARAMETER in it. which is ruining my query. is there any other way around to do….

i tried to dispose cmd after each query but of no use.. 🙁


          con.Open()
            Dim sqlTran As MySqlTransaction = con.BeginTransaction()
            Dim cmd As MySqlCommand = con.CreateCommand()
            cmd.Transaction = sqlTran
            Dim str As String = Nothing
            Try
                cmd.CommandText = "SELECT myid FROM memaster where    Adate=@adate and ANo=@ano and ASource=@asrc"
                cmd.Parameters.AddWithValue("@adate", txt_bpass_adate.Text)
                cmd.Parameters.AddWithValue("@ano", txt_bpass_af.Text)
                cmd.Parameters.AddWithValue("@asrc", txt_bpass_asource.Text)
                str = cmd.ExecuteScalar()
                'cmd.Dispose()'
                If str Is Nothing Then

                    cmd.CommandText = "Insert into memaster (ADate,ANo,ASource) values (@aDate,@aNo,@aSRC)"
                    cmd.Parameters.AddWithValue("@aDate", txt_bpass_adate.Text)
                    cmd.Parameters.AddWithValue("@aNo", txt_bpass_af.Text)
                    cmd.Parameters.AddWithValue("@aSRC", txt_bpass_asource.Text)

     cmd.ExecuteNonQuery()
    End If
     sqlTran.Commit()

            Catch ex As Exception
                Try
                    sqlTran.Rollback()
                Catch ex1 As Exception

                End Try
            End Try

i actually want to fire more then 4 queries in single transaction so that if anything go wrong i can rollback it…

if any onebody have any other method of it kindly share the concept wid me…


     For index As Integer = 1 To 5
                    cmd.CommandText = "Insert into detail (ID,BNos,SNo) values (@FID1,@BNo,@SeqN1)"
                    cmd.Parameters.AddWithValue("@FID1", str)
                    cmd.Parameters.AddWithValue("@BNo", str1)
                    cmd.Parameters.AddWithValue("@SeqN1", txt_bpass_sqn1.Text)
                    cmd.ExecuteNonQuery()


                Next
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T11:51:26+00:00Added an answer on June 17, 2026 at 11:51 am

    To execute multiple commands within the same transaction, ensure that you assign the transaction object to each command individually:

    Dim selectCmd As MySqlCommand = con.CreateCommand()
    Dim insertCmd As MySqlCommand = con.CreateCommand()
    
    selectCmd.CommandText = "SELECT ..."
    insertCmd.CommandText = "INSERT ..."
    
    Dim sqlTran As MySqlTransaction = con.BeginTransaction()
    Try
      selectCmd.Transaction = sqlTran
      insertCmd.Transaction = sqlTran
    
      ...selectCmd.ExecuteScalar()...
      ...insertCmd.ExecuteNonQuery()...
    
      sqlTran.Commit()
    Catch
      sqlTran.Rollback()
    End Try
    

    As others have mentioned, it is generally a good idea to Dispose() objects (that are IDisposable) as soon as you’re done working with them. After disposing objects, they can no longer be used.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using below code to show jquery dialog, its working perfectly, Sub OpenDialog(ByVal
I have the code below: using (SqlCommand command = new SqlCommand()) { command.CommandType =
im fetching an image from internet using the below code using an Async task,But
The code below works but I want to optimize the code using yield or
how to write the below code using struts2 tag library. since struts2 have many
I have just begun Rails 3. I have generated the below code using the
I have the below code: CODE BEHIND: using System; using System.Collections.Generic; using System.Linq; using
I have the below code which goes through and returns disk information. When running
I have the below code using System.Data.DataSetExtensions: var orderedTable = myDataTable.AsEnumerable().OrderBy(x=>x[ID].ToString()) myDataTable = orderedTable.CopyToDataTable();
i am able to send mail using below my code ,but by default after

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.