Chapter 11
Let's briefly recap how the ADO Cursor Engine performs updates. When you write code such as the following
strSQL = "SELECT CustomerID, CustomerName, BalanceDue " & _ "FROM Customers" With rsCustomers .CursorLocation = adUseClient .Open strSQL, cnDatabase, adOpenStatic, _ adLockOptimistic, adCmdText .Fields("BalanceDue") = 150 .Update End With |
ADO executes an action query that modifies the data in your database based on the changes you've made to your Recordset. In this case, the action query looks like this:
UPDATE Customers SET BalanceDue = 150 WHERE CustomerID = 7 AND BalanceDue = 100 |
To determine whether the query succeeded in updating the appropriate data, ADO examines the number of records affected by the action query. If at least one record was affected, ADO interprets this as a successful update. If no records were updated, ADO interprets this as a failed update because of a change made by another user. That record might have been deleted, or the value of the BalanceDue field might have changed. Such is the nature of optimistic updating.
You'll sometimes need more than just an action query, however. In some situations you'll want to retrieve data immediately after submitting a change to the database.