'Begin On Error GoTo ErrHandler: Dim objRs1 As New ADODB.Recordset Dim objRs2 As New ADODB.Recordset Dim strSQL As String Dim strMsg As String strSQL = "SELECT * FROM Shippers WHERE ShipperID = 2"’SQL查询 objRs1.CursorLocation = adUseClient’设置客户端游标 objRs1.Open strSQL, strConn, adOpenStatic, adLockBatchOptimistic, adCmdText’执行查询生成objrs1记录集 objRs1("Phone") = "(111) 555-1111"’更改表中一条记录phone字段的值 objRs2.Open strSQL, strConn, adOpenKeyset, adLockOptimistic, adCmdText’执行查询生成objrs2记录集 objRs2("Phone") = "(999) 555-9999" ’更改表中记录phone字段的值 objRs2.Update objRs2.Close Set objRs2 = Nothing On Error Resume Next objRs1.UpdateBatch If objRs1.ActiveConnection.Errors.Count <> 0 Then Dim intConflicts As Integer intConflicts = 0 objRs1.Filter = adFilterConflictingRecords intConflicts = objRs1.RecordCount objRs1.Resync adAffectGroup, adResyncUnderlyingValues If intConflicts > 0 Then strMsg = "A conflict occurred with updates for " & intConflicts & "records." & vbCrLf & "The values will be restored" " to their original values." objRs1.MoveFirst While Not objRs1.EOF strMsg = strMsg & "SHIPPER = " & objRs1("CompanyName") & vbCrLf strMsg = strMsg & "Value = " & objRs1("Phone").Value & vbCrLf strMsg = strMsg & "UnderlyingValue = " & _ objRs1("Phone").UnderlyingValue & vbCrLf strMsg = strMsg & "OriginalValue = " & _ objRs1("Phone").OriginalValue & vbCrLf strMsg = strMsg & vbCrLf & "Original value has been restored." MsgBox strMsg, vbOKOnly, _ "Conflict " & objRs1.AbsolutePosition & _ " of " & intConflicts objRs1("Phone").Value = objRs1("Phone").OriginalValue objRs1.MoveNext Wend objRs1.UpdateBatch adAffectGroup Else strMsg = "Errors occurred during the update. " & _ objRs1.ActiveConnection.Errors(0).Number & " " & _ objRs1.ActiveConnection.Errors(0).Description End If On Error GoTo 0 End If objRs1.MoveFirst objRs1.Close Set objRs1 = Nothing Exit Sub ErrHandler: If Not objRs1 Is Nothing Then If objRs1.State = adStateOpen Then objRs1.Close Set objRs1 = Nothing End If If Not objRs2 Is Nothing Then If objRs2.State = adStateOpen Then objRs2.Close Set objRs2 = Nothing End If If Err <> 0 Then MsgBox Err.Source & "-->" & Err.Description, , "Error" End If 'End 还可以使用当前 Record 的或特定 Field 的 Status 属性来确定已发生的冲突种类。