-
ERROR: EXECUTE READER REQUIRE THE COMMAND TO HAVE TRANSACTION WHEN....
Hi, I am trying Rollback and commit in my VB (VBA with ms access) Code but getting error-
CODE-
Dim tra As OleDb.OleDbTransaction = Nothing
Try
'inserting data into table
Dim myCmd As New OleDb.OleDbCommand
cn.open()
tra = cn.BeginTransaction()
myCmd.Connection = cn
myCmd.CommandText = "INSERT INTO query 1"
myCmd.Transaction = tra
myCmd.ExecuteNonQuery()
myCmd.CommandText = "INSERT INTO query 2" myCmd.ExecuteNonQuery()
tra.Commit()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error-" & Transaction_name, MessageBoxButtons.OK, MessageBoxIcon.Error)
tra.Rollback()
End Try
ERROR-
PLEASE HELP !!!!!!!!
-
Sorry, the majority of your code doesn't look like anything I am used to in Access VBA.
Are you working from outside Access?
-
OK MY BAD, Let me put my code here for you to analyse-
Dim tra As OleDb.OleDbTransaction = Nothing
Dim da4 As OleDb.OleDbDataAdapter
Dim dt4 As New DataTable
Dim myCmd As OleDb.OleDbCommand = cn.CreateCommand()
Try
ConnectDatabase(CSS_FE_DB_PATH)
tra = cn.BeginTransaction()
myCmd.Transaction = tra
myCmd.Connection = cn
myCmd.CommandText = "INSERT Query 1........."
myCmd.ExecuteNonQuery()
da4 = New OleDb.OleDbDataAdapter("SELECT Query....., cn)
da4.Fill(dt4)
myCmd.CommandText = "INSERT INTO query 2........."
myCmd.ExecuteNonQuery()
ra.Commit()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error-" & Transaction_name, MessageBoxButtons.OK, MessageBoxIcon.Error)
tra.Rollback()
End Try
Error- Execute Reader require the command to have a transaction when the connection assigned to the command is in a pending local transaction. the transaction property of the command has not be initialized
My Guess is this has something to do with the SELECT Query code right after Insert Statement. Can you help now !
-
No, sorry, I am only familiar with Access based VBA, not with code from an external source.
Your code does not look correct for initiating an Insert query.
I would normally use a Recordset to add data to an access table.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules