Article ID: 190727
Article Last Modified on 6/29/2004
rsCustomers.CursorLocation = adUseClient
rsCustomers.Open "SELECT * FROM Customers", cnNWind, _
adOpenStatic, adLockOptimistic, adCmdText
rsCustomers.Fields("CompanyName").Value = "Acme"
rsCustomers.Update
will cause ADO to execute the following action query
UPDATE Customers SET CompanyName = 'Acme'
WHERE CustomerID = 'ALFKI' AND CompanyName = 'Alfreds Futterkiste'
The WHERE clause contains information about the primary key and the
original value for the field to update. This ensures that if another user has
modified the value of the CompanyName field to a value other than the value
that ADO originally retrieved, ADO will not update that row and will raise an
error instead.
rsCustomers.CursorLocation = adUseClient
rsCustomers.Properties("Update Criteria").Value = adCriteriaAllCols
rsCustomers.Open "SELECT * FROM Customers", cnNWind, _
adOpenStatic, adLockOptimistic, adCmdText
rsCustomers.Fields("CompanyName").Value = "Acme"
rsCustomers.Update
This code will cause ADO to include every field in the WHERE clause.
You would use this value for the "Update Criteria" property if you want to make
sure that the update made by the current user will only succeed if no changes
have been made to any fields in that row in the table.
adCriteriaKey = 0
Uses only the primary key
adCriteriaAllCols = 1
Uses all columns in the recordset
adCriteriaUpdCols = 2 (Default)
Uses only the columns in the recordset that have been modified
adCriteriaTimeStamp = 3
Uses the timestamp column (if available) in the recordset
NOTE: Specifying adCriteriaTimeStamp may actually use
adCriteriaAllCols method to execute the Update if there is not a valid
TimeStamp field in the table. Also, the timestamp field does not need to be in
the recordset itself. 301248 How To Update a Database from a DataSet Object by Using Visual Basic .NET
Keywords: kbhowto kbdatabase KB190727