A
alobi
Guest
I have this code below, it runs without error as far as I can tell. At the end it pops up a message that "Both Records are written the table" but it actually does not save any value in DB. I am been working with this for two day and still getting the same result. Pls help.
Private Sub Testtransaction_Click(sender As Object, e As EventArgs) Handles Testtransaction.Click
Dim conn As New OleDbConnection
Dim cmd As New OleDb.OleDbCommand
conn.ConnectionString = getConnection()
Dim transaction As OleDbTransaction = Nothing
'connection to New oledb Connectiont
cmd.Connection = conn
'open connection and execute transaction
conn.Open()
Try
transaction = conn.BeginTransaction(IsolationLevel.ReadCommitted)
cmd.Connection = conn
cmd.Transaction = transaction
'execute the commands
cmd.CommandText = "INSERT INTO RegPat(Titl) Values(?)"
cmd.Parameters.AddWithValue("?", cboTitle.Text)
cmd.ExecuteNonQuery()
cmd.Parameters.Clear()
cmd.CommandText = "INSERT INTO RegNoK(Title)Values(?)"
cmd.Parameters.AddWithValue("?", CboTitleNok.Text)
cmd.ExecuteNonQuery()
transaction.Commit()
Catch ex As Exception
transaction.Rollback()
End Try
'transaction.Commit()
MsgBox("Both Records Are Written to the tables")
End Sub
Continue reading...
Private Sub Testtransaction_Click(sender As Object, e As EventArgs) Handles Testtransaction.Click
Dim conn As New OleDbConnection
Dim cmd As New OleDb.OleDbCommand
conn.ConnectionString = getConnection()
Dim transaction As OleDbTransaction = Nothing
'connection to New oledb Connectiont
cmd.Connection = conn
'open connection and execute transaction
conn.Open()
Try
transaction = conn.BeginTransaction(IsolationLevel.ReadCommitted)
cmd.Connection = conn
cmd.Transaction = transaction
'execute the commands
cmd.CommandText = "INSERT INTO RegPat(Titl) Values(?)"
cmd.Parameters.AddWithValue("?", cboTitle.Text)
cmd.ExecuteNonQuery()
cmd.Parameters.Clear()
cmd.CommandText = "INSERT INTO RegNoK(Title)Values(?)"
cmd.Parameters.AddWithValue("?", CboTitleNok.Text)
cmd.ExecuteNonQuery()
transaction.Commit()
Catch ex As Exception
transaction.Rollback()
End Try
'transaction.Commit()
MsgBox("Both Records Are Written to the tables")
End Sub
Continue reading...