Update 方法Update Method

保存对记录对象的当前行所做的任何更改,或记录对象的字段集合。Saves any changes you make to the current row of a Recordset object, or the Fields collection of a Record object.

语法Syntax

  
recordset.Update Fields, Values  
record.Fields.Update  

参数Parameters

FieldsFields
可选。Optional. 表示单个名称的 变量 ,或表示要修改的一个或多个字段的名称或序号位置的 variant 数组。A Variant that represents a single name, or a Variant array that represents names or ordinal positions of the field or fields you wish to modify.

Values
可选。Optional. 一个表示单个值的 变量 ,或一个表示新记录中的一个或多个字段的值的 变体 数组。A Variant that represents a single value, or a Variant array that represents values for the field or fields in the new record.

备注Remarks

记录集Recordset

使用 Update 方法保存对 记录集 对象的当前记录所做的任何更改,因为调用了 AddNew 方法或更改了现有记录中的任何字段值。Use the Update method to save any changes you make to the current record of a Recordset object since calling the AddNew method or since changing any field values in an existing record. Recordset 对象必须支持更新。The Recordset object must support updates.

若要设置字段值,请执行以下操作之一:To set field values, do one of the following:

  • 字段 对象的 Value 属性赋值,并调用 Update 方法。Assign values to a Field object's Value property and call the Update method.

  • 使用 更新 调用作为参数传递字段名称和值。Pass a field name and a value as arguments with the Update call.

  • 使用 更新 调用传递字段名称和值数组的数组。Pass an array of field names and an array of values with the Update call.

使用字段和值的数组时,两个数组中的元素数必须相等。When you use arrays of fields and values, there must be an equal number of elements in both arrays. 并且字段名称的顺序必须与字段值的顺序匹配。Also, the order of field names must match the order of field values. 如果字段和值的数量和顺序不匹配,将发生错误。If the number and order of fields and values do not match, an error occurs.

如果 Recordset 对象支持批处理更新,则可以在调用 UpdateBatch 方法之前,将多个更改缓存到本地一个或多个记录。If the Recordset object supports batch updating, you can cache multiple changes to one or more records locally until you call the UpdateBatch method. 如果在调用 UpdateBatch 方法时编辑当前记录或添加新记录,ADO 将自动调用 Update 方法,以便在将批处理更改传输到提供程序之前保存当前记录的所有挂起的更改。If you are editing the current record or adding a new record when you call the UpdateBatch method, ADO will automatically call the Update method to save any pending changes to the current record before transmitting the batched changes to the provider.

如果在调用 update 方法之前从要添加或编辑的记录中移动,ADO 将自动调用 update 以保存更改。If you move from the record you are adding or editing before calling the Update method, ADO will automatically call Update to save the changes. 如果要取消对当前记录所做的任何更改,或者放弃新添加的记录,则必须调用 CancelUpdate 方法。You must call the CancelUpdate method if you want to cancel any changes made to the current record or discard a newly added record.

在调用 Update 方法之后,当前记录保持为最新。The current record remains current after you call the Update method.

记录Record

Update 方法完成对 Record 对象的 fields集合中的字段的添加、删除和更新。The Update method finalizes additions, deletions, and updates to fields in the Fields collection of a Record object.

例如, 删除方法删除的字段 会立即标记为删除,但仍保留在集合中。For example, fields deleted with the Delete method are marked for deletion immediately but remain in the collection. 若要实际从提供程序的集合中删除这些字段,必须调用 Update 方法。The Update method must be called to actually delete these fields from the provider's collection.

应用于Applies To

另请参阅See Also

Update 和 CancelUpdate 方法示例 (VB) Update and CancelUpdate Methods Example (VB)
Update 和 CancelUpdate 方法示例 (VC + +) Update and CancelUpdate Methods Example (VC++)
AddNew 方法 (ADO) AddNew Method (ADO)
CancelUpdate 方法 (ADO) CancelUpdate Method (ADO)
EditMode 属性 EditMode Property
UpdateBatch 方法UpdateBatch Method