BEGINTRANS, COMMIT ECC...

User avatar
sal21
PlatinumLounger
Posts: 4368
Joined: 26 Apr 2010, 17:36

BEGINTRANS, COMMIT ECC...

Post by sal21 »

I have this part of code i fill two recordset in to same routine, and i want to use begintrans committ... rolbaktrans..ecc:
is correct code1 or code2

code1
conn.begintrans
.....
rs.addnew
rs.=fff
..
rs.update
conn.committ

begintrans ...
rs1.addnew
rs1.=fff
..
rs1.update
....
conn.committ
error trap:

conn.rollbacktrans


code2

conn.begintrans

.....
rs.addnew
rs.=fff
..
rs.update
...
rs1.addnew
rs1.=fff
..
rs1.update
....
conn.committ

error trap:

conn.rollbacktrans

User avatar
HansV
Administrator
Posts: 78589
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: BEGINTRANS, COMMIT ECC...

Post by HansV »

It depends on what you want.

If something goes wrong while rs1 is being updated, the first routine will undo only the changes to rs1, but those to rs will remain. The second routine will undo the changes to both rs and rs1.

YOU will have to decide what is best for your situation.
Best wishes,
Hans