PRB: WillChangeRecord Event Does Not Fire on Update
ID: Q189365
|
The information in this article applies to:
-
ActiveX Data Objects (ADO), versions 2.0, 2.1 SP2
SYMPTOMS
When issuing a Recordset.Update, the WillChangeRecord event does not fire.
CAUSE
Whether this event fires or not depends on the type of cursor opened. If
the locking schema for the cursor is adLockBatchOptimistic then this event
will not fire on Recordset.Update; instead it fires on UpdateBatch.
STATUS
This behavior is by design.
MORE INFORMATION
Steps to Reproduce Behavior
- Create a new Visual Basic Project.
- Set a Project Reference to the Microsoft ActiveX Data Objects Library.
- Select the default form to open the Code window.
- Delete the Form_Load code.
- Copy and paste the following into the Code window:
Dim oCn As Connection
Dim WithEvents oRs As Recordset
Dim oCm As Command
Private Sub Form_Load()
Set oCn = New Connection
Set oRs = New Recordset
Set oCm = New Command
With oCn
.ConnectionString = "PROVIDER=SQLOLEDB;" & _
"DATA SOURCE=matthofa;" & _
"Initial Catalog=pubs;" & _
"User Id=sa;Password="
.Open
End With
With oCm
Set .ActiveConnection = oCn
.CommandText = "select * from authors"
.CommandType = adCmdText
End With
With oRs
Set .ActiveConnection = oCn
.CursorLocation = adUseClient
.CursorType = adOpenStatic
.LockType = adLockBatchOptimistic
.Open oCm
End With
oRs(1) = "something new"
oRs.Update
oRs.UpdateBatch
End Sub
Private Sub oRs_WillChangeRecord _
(ByVal adReason As ADODB.EventReasonEnum, _
ByVal cRecords As Long, _
adStatus As ADODB.EventStatusEnum, _
ByVal pRecordset As ADODB.Recordset)
MsgBox "oRs_WillChangeRecord"
End Sub
- Modify the connection string to point to your server.
Step through the program. The WillChangeRecord event is fired on
oRs(1) = "something new" and oRs.UpdateBatch, but not on oRS.Update.
Additional query words:
Keywords : kbADO200 kbDatabase kbVBp600 kbGrpVBDB kbGrpMDAC kbDSupport kbMDAC200 kbADO210sp2 kbMDAC210SP2
Version : WINDOWS:2.0,2.1 SP2
Platform : WINDOWS
Issue type : kbprb