Of course, the ADO Cursor Engine wouldn't be widely accepted unless you could use it to update the data in your database. You can update your database by simply modifying the appropriate field in the recordset and calling the Recordset object's Update method, as follows:
strSQL = "SELECT CustomerID, CustomerName, BalanceDue FROM Customers" rsCustomers.CursorLocation = adUseClient rsCustomers.Open strSQL, cnDatabase, adOpenStatic, adLockOptimistic rsCustomers.Fields("BalanceDue") = rsCustomers.Fields("BalanceDue") + 50 rsCustomers.Update |
The ADO Cursor Engine also includes the ability to cache updates you make to your Recordset object and send them to your database in a batch at a later time by calling the UpdateBatch method. You'll notice that the previous code used the adLockOptimistic constant in the call to the Recordset's Open method. The following code uses adLockBatchOptimistic in the call to Open so the database isn't updated until UpdateBatch is called. For more information, see the "LockType Property" section in Chapter 4.
strSQL = "SELECT CustomerID, CustomerName, BalanceDue FROM Customers" rsCustomers.CursorLocation = adUseClient rsCustomers.Open strSQL, cnDatabase, adOpenStatic, adLockBatchOptimistic rsCustomers.Fields("BalanceDue") = rsCustomers.Fields("BalanceDue") + 50 rsCustomers.Update rsCustomers.MoveNext rsCustomers.Fields("BalanceDue") = _ rsCustomers.Fields("BalanceDue") + 125 rsCustomers.Update rsCustomers.UpdateBatch |
In Chapter 10, you'll see in much greater detail how ADO updates the data in your database.