ADO Append Method

Home | About me | EXCEL VB Programming (XL97-2003) | ACCESS Programming | EXCEL VB.Net Programming | EXCEL Spreadsheet Functions Material Management  |  Guestbook
 

ADO Append Method

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.

Using this method, you can both append and assign a value to the object at the same time. This is useful, because the Value property must first be set and an Update must have occured, before you can set any other properties. There are three data types for the Field object that cannot be appended to the Fields Collection. If you try to use adArray, adChapter, or adEmpty, an error will occur.

Applies To :
Fields Collection
Parameters Collection

Syntax

Fields.Append Name, Type, DefineSize, Attrib, FieldValue
 

This method has five optional parameters.  

Parameter Description
Name The optional Name is the unique name of the new Field object being appended to the collection.
Type The optional Type is one of the DataTypeEnum constants that defines the data type of the new Field.
DefinedSize The optional DefinedSize parameter is a long value that is the size in bytes or characters of the new Field. When DefinedSize exceeds 255 bytes, the field is treated as having variable length columns.
Attrib The optional Attrib parameter is one of the FieldAttributeEnum constants that specify the attributes of the new Field.
FieldValue The optional FieldValue parameter is a variant that is the value for the new Field. If this parameter is not provided, it will be set to null when the new Field is appended.

Example

objRecord.Fields.Append "Age", adInteger

Parameters Collection:
You must set the Type property of a Parameter object before appending it to the Parameters collection. 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.

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:
The FieldValue parameter is only valid when adding a Field object to a Record object, not to a Recordset object. With a Record object, you can append fields and provide values at the same time. With a Recordset object, you must create fields while the Recordset is closed, and then open the Recordset and assign values to the fields.

Note:
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. Field 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. Also, 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.

DataTypeEnum Constants

Constant Value

Description

adArray 0x2000 Combine with another data type to indicate that the other data type is an array
adBigInt 20 8-byte signed integer
adBinary 128 Binary
adBoolean 11 True or false Boolean
adBSTR 8 Null-terminated character string
adChapter 136 4-byte chapter value for a child recordset
adChar 129 String
adCurrency 6 Currency format
adDate 7 Number of days since 12/30/1899
adDBDate 133 YYYYMMDD date format
adDBTime 134 HHMMSS time format
adDBTimeStamp 135 YYYYMMDDHHMMSS date/time format
adDecimal 14 Number with fixed precision and scale
adDouble 5 Double precision floating-point
adEmpty 0 no value
adError 10 32-bit error code
adFileTime 64 Number of 100-nanosecond intervals since 1/1/1601
adGUID 72 Globally unique identifier
adIDispatch 9 Currently not supported by ADO
adInteger 3 4-byte signed integer
adIUnknown 13 Currently not supported by ADO
adLongVarBinary 205 Long binary value
adLongVarChar 201 Long string value
adLongVarWChar 203 Long Null-terminates string value
adNumeric 131 Number with fixed precision and scale
adPropVariant 138 PROPVARIANT automation
adSingle 4 Single-precision floating-point value
adSmallInt 2 2-byte signed integer
adTinyInt 16 1-byte signed integer
adUnsignedBigInt 21 8-byte unsigned integer
adUnsignedInt 19 4-byte unsigned integer
adUnsignedSmallInt 18 2-byte unsigned integer
adUnsignedTinyInt 17 1-byte unsigned integer
adUserDefined 132 User-defined variable
adVarBinary 204 Binary value
adVarChar 200 String
adVariant 12 Automation variant
adVarNumeric 139 Variable width exact numeric with signed scale
adVarWChar 202 Null-terminated Unicode character string
adWChar 130 Null-terminated Unicode character string

 
FieldAttributeEnum Constants  
 
Constant Value

Description

adFldCacheDeferred 0x1000 Provider caches values and reads from cache
adFldFixed 0x10 Fixed-length data
adFldIsChapter 0x2000 Chapter value with specified child recordset
adFldIsCollection 0x40000 Collection of resources
adFldIsDefaultStream 0x20000 Contains default stream
adFldIsNullable 0x20 Accepts null values
adFldIsRowURL 0x10000 Contains URL to resource in data source
adFldKeyColumn 0x8000 Primary key or part of primary key
adFldLong 0x80 Long binary field and can use AppendChunk and GetChunk methods
adFldMayBeNull 0x40 Can read null values
adFldMayDefer 0x2 Values are not retrieved with whole record
adFldNegativeScale 0x4000 Can support negative scale values
adFldRowID 0x100 Contains a row identifier used only to ID the row
adFldRowVersion 0x200 Uses time/date to track updates
adFldUnknownUpdatable 0x8 Provider cannot determine if you can write to field
adFldUnspecified -1 Does not specify attributes
adFldUpdatable 0x4 Can write to field