Public Sub main()Dim conn As New ADODB.Connection Dim cmd As New ADODB.Command Dim rs As New ADODB.Recordset ‘步骤 1 conn.Open "DSN=pubs;uid=sa;pwd=;database=pubs" ‘步骤 2 Set cmd.ActiveConnection = conn cmd.CommandText = "SELECT * from authors" ‘步骤 3 rs.CursorLocation = adUseClient rs.Open cmd, , adOpenStatic, adLockBatchOptimistic ‘步骤 4 rs("au_lname").Properties("Optimize") = True rs.Sort = "au_lname" rs.Filter = "phone LIKE '415 5*'" rs.MoveFirst Do While Not rs.EOF Debug.Print "Name: " & rs("au_fname") & " "; rs("au_lname") & _ "Phone: "; rs("phone") & vbCr rs("phone") = "777" & Mid(rs("phone"), 5, 11) rs.MoveNext Loop‘步骤 5 conn.BeginTrans‘步骤 6 - A On Error GoTo ConflictHandler rs.UpdateBatch On Error GoTo 0conn.CommitTransExit Sub‘ 步骤 6 - B ConflictHandler:rs.Filter = adFilterConflictingRecords rs.MoveFirst Do While Not rs.EOF Debug.Print "Conflict: Name: " & rs("au_fname"); " " & rs("au_lname") rs.MoveNext Loop conn.Rollback Resume NextEnd Sub
Visual Basic 教程到此结束。