Sun Chili!Soft ASP Sun Chili!Soft
ASP Sun Microsystems

 

ADO Recordset Object CancelBatch Method

Cancels a pending batch update. This method is not currently supported on UNIX.

CancelBatch Method Syntax

recordset.CancelBatch AffectRecords

CancelBatch Method Parameters

AffectRecords

An optional AffectEnum value that determines how many records the CancelBatch method will affect. It can be one of the following constants:

Constant

Description

adAffectCurrent

Cancels pending updates only for the current record.

adAffectGroup

Cancels pending updates for records that satisfy the current ADO Recordset Object Filter Property setting. You must set the Filter property to one of the valid predefined constants in order to use this option.

adAffectAll

Default. Cancels pending updates for all the records in the Recordset object, including any hidden by the current Filter property setting.

CancelBatch Method Remarks

Use the CancelBatch method to cancel any pending updates in a recordset in batch update mode. If the recordset is in immediate update mode, calling CancelBatch without adAffectCurrent generates an error.

If you are editing the current record or are adding a new record when you call CancelBatch, ADO first calls the ADO Recordset Object CancelUpdate Method to cancel any cached changes; after that, all pending changes in the recordset are canceled.

It's possible that the current record will be indeterminable after a CancelBatch call, especially if you were in the process of adding a new record. For this reason, it is prudent to set the current record position to a known location in the recordset after the CancelBatch call. For example, call the ADO Recordset Object MoveFirst, MoveLast, MoveNext, and MovePrevious Methods.

If the attempt to cancel the pending updates fails because of a conflict with the underlying data (for example, a record has been deleted by another user), the provider returns warnings to the ADO Errors Collection but does not halt program execution. A run-time error occurs only if there are conflicts on all the requested records. Use the Filter property (adFilterAffectedRecords) and the ADO Recordset Object Status Property to locate records with conflicts.

CancelBatch Method Examples

This Visual Basic example demonstrates the ADO Recordset Object UpdateBatch Method in conjunction with the CancelBatch method.

Public Sub UpdateBatchX()

Dim rstTitles As ADODB.Recordset

Dim strCnn As String

Dim strTitle As String

Dim strMessage As String

` Assign connection string to variable.

strCnn = "driver={SQL Server};server=srv;" & _

"uid=sa;pwd=;database=pubs"

Set rstTitles = New ADODB.Recordset

rstTitles.CursorType = adOpenKeyset

rstTitles.LockType = adLockBatchOptimistic

rstTitles.Open "titles", strCnn, , , adCmdTable

rstTitles.MoveFirst

` Loop through recordset and ask user if she wants

` to change the type for a specified title.

Do Until rstTitles.EOF

If Trim(rstTitles!Type) = "psychology" Then

strTitle = rstTitles!Title

strMessage = "Title: " & strTitle & vbCr & _

"Change type to self help?"

If MsgBox(strMessage, vbYesNo) = vbYes Then

rstTitles!Type = "self_help"

End If

End If

rstTitles.MoveNext

Loop

` Ask if the user wants to commit to all the

` changes made above.

If MsgBox("Save all changes?", vbYesNo) = vbYes Then

rstTitles.UpdateBatch

Else

rstTitles.CancelBatch

End If

` Print current data in recordset.

rstTitles.Requery

rstTitles.MoveFirst

Do While Not rstTitles.EOF

Debug.Print rstTitles!Title & " - " & rstTitles!Type

rstTitles.MoveNext

Loop

` Restore original values because this is a demonstration.

rstTitles.MoveFirst

Do Until rstTitles.EOF

If Trim(rstTitles!Type) = "self_help" Then

rstTitles!Type = "psychology"

End If

rstTitles.MoveNext

Loop

rstTitles.UpdateBatch

rstTitles.Close

End Sub

Copyright 2002 Sun Microsystems, Inc. All rights reserved. Legal Notice.