Append 方法 (ADO)Append Method (ADO)

将对象追加到集合。Appends an object to a collection. 如果集合是 字段,则可在将新字段对象追加到集合之前创建新的 字段 对象。If the collection is Fields, a new Field object can be created before it is appended to the collection.

语法Syntax

  
collection.Append object  
fields.Append Name, Type, DefinedSize, Attrib, FieldValue  

参数Parameters

集合collection
集合对象。A collection object.

字段fields
字段 集合。A Fields collection.

objectobject
一个对象变量,表示要追加的对象。An object variable that represents the object to be appended.

名称Name
一个包含新 字段 对象名称的 字符串 值,不能与 字段 中的任何其他对象同名。A String value that contains the name of the new Field object, and must not be the same name as any other object in fields.

类型Type
一个 DataTypeEnum 值,其默认值为 adEmpty,指定新字段的数据类型。A DataTypeEnum value, whose default value is adEmpty, that specifies the data type of the new field. ADO 不支持以下数据类型,不应在将新字段追加到 记录集对象 (ado)adIDispatchadIUnknownadVariant 时使用。The following data types are not supported by ADO, and should not be used when appending new fields to a Recordset Object (ADO): adIDispatch, adIUnknown, adVariant.

DefinedSizeDefinedSize
可选。Optional. 一个 长整型 值,表示新字段的定义的大小(以字符或字节为单位)。A Long value that represents the defined size, in characters or bytes, of the new field. 此参数的默认值是从 类型 派生的。The default value for this parameter is derived from Type. 具有大于255字节的 DefinedSize 的字段将被视为可变长度列。Fields that have a DefinedSize greater than 255 bytes are treated as variable length columns. 未指定 DefinedSize 的默认值。The default for DefinedSize is unspecified.

恶性Attrib
可选。Optional. 一个 FieldAttributeEnum 值,其默认值为 adFldDefault,用于指定新字段的特性。A FieldAttributeEnum value, whose default value is adFldDefault, that specifies attributes for the new field. 如果未指定此值,则字段将包含派生自 类型 的特性。If this value is not specified, the field will contain attributes derived from Type.

FieldValueFieldValue
可选。Optional. 一个表示新字段的值的 变量A Variant that represents the value for the new field. 如果未指定,则使用 null 值追加字段。If not specified, the field is appended with a null value.

备注Remarks

Parameters 集合Parameters Collection

必须先设置参数对象的Type属性,然后再将其追加到Parameters集合。You must set the Type property of a Parameter object before appending it to the Parameters collection. 如果选择可变长度的数据类型,则还必须将 " Size " 属性设置为大于零的值。If you select a variable-length data type, you must also set the Size property to a value greater than zero.

使用存储过程或参数化查询,自行描述参数可最大程度地减少对提供程序的调用,从而提高性能。Describing parameters yourself minimizes calls to the provider and therefore improves performance when you use stored procedures or parameterized queries. 但是,您必须知道与要调用的存储过程或参数化查询相关联的参数的属性。However, you must know the properties of the parameters associated with the stored procedure or parameterized query that you want to call.

使用 CreateParameter 方法创建具有相应属性设置的 参数 对象,并使用 Append 方法将它们添加到 Parameters 集合。Use the CreateParameter method to create Parameter objects with the appropriate property settings and use the Append method to add them to the Parameters collection. 这使你可以设置和返回参数值,而无需调用提供程序来获取参数信息。This lets you set and return parameter values without having to call the provider for the parameter information. 如果要写入未提供参数信息的提供程序,则必须使用此方法手动填充 参数 集合以使用参数。If you are writing to a provider that does not supply parameter information, you must use this method to manually populate the Parameters collection in order to use parameters at all.

字段集合Fields Collection

仅当向 记录对象添加 字段 对象,而不是 记录集 对象时, FieldValue 参数才有效。The FieldValue parameter is only valid when adding a Field object to a Record object, not to a Recordset object. 使用 Record 对象,可以同时追加字段并提供值。With a Record object, you can append fields and provide values at the same time. 对于 recordset 对象,您必须在 记录集 关闭时创建字段,然后打开该 记录集 并向字段分配值。With a Recordset object, you must create fields while the Recordset is closed, and then open the Recordset and assign values to the fields.

备注

对于附加到 Record 对象的 Fields 集合的新 字段 对象,必须先设置 Value属性,然后才能指定任何其他 字段 属性。For new Field objects that have been appended to the Fields collection of a Record object, the Value property must be set before any other Field properties can be specified. 首先,必须在名为的 字段 集合上分配和 更新 属性的特定值。First, a specific value for the Value property must have been assigned and Update on the Fields collection called. 然后,可以访问其他属性,例如 类型属性Then, other properties such as Type or Attributes can be accessed. 以下数据 (类型的****字段 对象无法追加到 DataTypeEnum) ,并且将导致发生错误: adArrayadChapteradEmptyadPropVariantadUserDefinedField objects of the following data types (DataTypeEnum) cannot be appended to the Fields collection and will cause an error to occur: adArray, adChapter, adEmpty, adPropVariant, and adUserDefined. 此外,ADO 不支持以下数据类型: adIDispatchadIUnknownadIVariantAlso, the following data types are not supported by ADO: adIDispatch, adIUnknown, and adIVariant. 对于这些类型,追加时不会发生错误,但使用可能产生不可预知的结果,包括内存泄漏。For these types, no error will occur when appended, but usage can produce unpredictable results including memory leaks.

记录集Recordset

如果在调用 Append 方法之前未设置 CursorLocation属性,则在调用 Recordset对象的 Open方法时, CursorLocation 将设置为 adUseClient (一个 CursorLocationEnum值自动) 。If you do not set the CursorLocation property before calling the Append method, CursorLocation will be set to adUseClient (a CursorLocationEnum value) automatically when the Open method of the Recordset object is called.

如果对打开的 记录集字段 集合或已设置 ActiveConnection属性的 记录集 调用 Append 方法,将会发生运行时错误。A run-time error will occur if the Append method is called on the Fields collection of an open Recordset, or on a Recordset where the ActiveConnection property has been set. 您只能向未打开且尚未连接到数据源的 记录集 追加字段。You can only append fields to a Recordset that is not open and has not yet been connected to a data source. 当使用 CreateRecordset方法制造 Recordset 对象或将其分配给对象变量时,通常会出现这种情况。This is typically the case when a Recordset object is fabricated with the CreateRecordset method or assigned to an object variable.

记录Record

如果对打开的 记录字段 集合调用 Append 方法,则不会发生运行时错误。A run-time error will not occur if the Append method is called on the Fields collection of an open Record. 新字段将添加到 Record 对象的 "字段" 集合中。The new field will be added to the Fields collection of the Record object. 如果 记录 是从 记录集 派生的,则新字段将不会出现在 recordset 对象的 "字段" 集合中。If the Record was derived from a Recordset, the new field will not appear in the Fields collection of the Recordset object.

通过将值分配给字段对象,可以创建不存在的字段并将其追加到 字段集合中 ,就像它已存在于集合中一样。A non-existent field can be created and appended to the Fields collection by assigning a value to the field object as if it already existed in the collection. 分配将触发 字段 对象的自动创建和追加,然后将完成分配。The assignment will trigger the automatic creation and appending of the Field object, and then the assignment will be completed.

字段 追加到 Record 对象的 Fields 集合后,调用 fields 集合的 Update 方法来保存更改。After appending a Field to the Fields collection of a Record object, call the Update method of the Fields collection to save the change.

应用于Applies To

另请参阅See Also

Append 和 CreateParameter 方法示例 (VB) Append and CreateParameter Methods Example (VB)
附加和 CreateParameter 方法示例 (VC + +) Append and CreateParameter Methods Example (VC++)
CreateParameter 方法 (ADO) CreateParameter Method (ADO)
(ADO 字段集合的 Delete 方法) Delete Method (ADO Fields Collection)
(ADO 参数集合的 Delete 方法) Delete Method (ADO Parameters Collection)
ADO 记录集 (Delete 方法) Delete Method (ADO Recordset)
Update 方法Update Method