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
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.