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