Click here to Skip to main content
15,888,119 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I use a autonumbered MS.Access table to store transactions in my VB.net application.

I insert data within a Begin/Commit/Rollback loop.

Doing a series of tranactions, after I insert a record by using

Dim pCmd As New OleDb.OleDbCommand(sQ, oCn, oTr)
     pCmd.ExecuteNonQuery()


I need to get the autonumber of the first transaction to use it as a pointer for the next few child transactions.

However using Max(Id) on the Transaction Table does not work always correctly as I cannot determine if ExecuteNonQuery is complete?

Is there any way to determine that the table is updated?

Hope that makes sense.

Meenog

What I have tried:

ExecuteNonQuery returns the number of rows updated but immediately querying Max(Id) of the table usually returns the immediately previous row number.
Posted
Updated 27-Nov-18 0:29am
Comments
W Balboos, GHB 26-Nov-18 14:25pm    
Try running this without wrapping it in a transaction - if it works than adjust your code/query order appropriately.

After further mining of the www I found the solution as follows:

Dim pCmd As New OleDb.OleDbCommand(sQ, oCn, oTr)
pCmd.ExecuteNonQuery()
pCmd.CommandText = "SELECT @@Identity"
parent = CInt(pCmd.ExecuteScalar)

where parent is the Autonumber Id of the Inserted Row.
 
Share this answer
 
Thanks, Balboos, but because they are related I need to wrap them. Basically what I'm asking is is there anyway to determine if the ExecuteNonQuery is completed. It used not be a problem in ADO.
 
Share this answer
 
Comments
Richard Deeming 27-Nov-18 11:31am    
If you want to reply to a comment, click the "Reply" button next to that comment. DO NOT post your reply as a "solution".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900