PDA

View Full Version : ADO UpdateBatch


charon
05-13-2003, 05:20 AM
hi,
The UpdateBatch method is used to save all changes in a Recordset to the database. Just assume that
I have 10 records to save and all these records must save at the same time, if one fail, all must
fail. i.e:

For k = 1 to numRecord
objRS.AddNew
objRS("Name") = Name
objRS("IC") = Ic
objRS("Job") = Job


objRS.MoveNext
Next
objRS.UpdateBatch
In order to make sure that either UPDATE ALL or NOT UPDATE ALL, I'm thinking of use ADO UpdateBatch method,
is it OK????? Good way??

Roy Sinclair
05-13-2003, 02:19 PM
In order to make all updates occur or no updates occur use a "BEGIN TRANSACTION GOTSOMEUPDATES" before the loop and after the loop do a "COMMIT TRANSACTION GOTSOMEUPDATES".

By wrapping all the updates in a TRANSACTION, they will either all be done or none of them will be done.

You also need to check for errors during the update process, if you detect an error you should run "ROLLBACK TRANSACTION GOTSOMEUPDATES" instead of the commit.

charon
05-15-2003, 05:50 AM
1.)then what about UpdateBatch method, it won't help "either all be done or none of them will be done"????


2.) if question 1 is correct, then the UpdateMethod is just like normal Update Method, the different is just it updates all changes "at the same time". CORRECT???

3.) I can use BeginTrans here??
objRS.Open sql, Con
BeginTrans
For k = 1 to numRecord
objRS.AddNew
objRS("Name") = Name
objRS("IC") = Ic
objRS("Job") = Job


objRS.MoveNext
Next
objRS.UpdateBatch

If Con.Errors.Count <> 0 Then
Con.Rollbacktrans
Else
Con.Committrans
End If


or I must use Con.Execute "Update Statement"

pls advice!