Field Object
Record Object
COLLECTION: Record::Fields Collection
Implemented in version 2.5
The
Fields Collection
is a collection of all of the
Field
objects associated with a specific
Record
object.
The
Fields Collection
has a wider selection of methods than the various other collections in ADO. For example, the
Append
method allows you to add
Field
objects to the collection and the
Update
and
CancelUpdate
methods give you control over updates.
If you reference by name a
Field
object that does not exist, a new
Field
object with that name will be appended automatically to the
Fields Collection
. The
Status
property for this newly appended
Field
will be assigned a
FieldStatusEnum
value of
adFieldPendingInsert
. Further, if allowed by your provider, the
Field
will be created in the data source the next time you call the
Update
method.
There are two special fields which can be referenced in a
Record
object by using the
FieldEnum
constants.
FieldEnum Constants
Constant
Value
Description
adDefaultStream
-1
References the field containing the default stream
adRecordURL
-2
References the field containing the absolute URL
A
Recordset
object can also have a
Fields Collection
.
The
Fields Collection
has two properties and six methods.
PROPERTIES
Count Property
The
Count
property returns a long value that is the number of items in the collection. The counting starts at zero. You can use this value to loop throught the collection by iterating from zero to the value of
Count
minus one.
Code (VBScript):
intCountNumber = objRecord.Fields.
Count
You can also use the VB/VBScript
For Each ... Next
statement.
Code (VBScript):
For Each objField In objRecord.Fields
' place code here to manipulate each item in collection
Next
Item Property
The
Item
property is used to return a specific member of the
fields Collection
. The
Index
parameter is a variant. It can be the named item or the position (ordinal) number.
Code (VBScript):
MyProperty = objRecord.Fields.
Item(5)
Or:
MyProperty = objRecord.Fields
(5)
Or:
MyProperty = objRecord.Fields
("Transaction DDL")
METHODS
Append Method
The
Append
method is used to add (append) a
Field
object to the
Fields 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.
syntax:
Fields.
Append
Name, Type, DefineSize, Attrib, FieldValue
This method has five optional parameters.
The optional
Name
is the unique name of the new
Field
object being appended to the collection.
The optional
Type
is one of the
DataTypeEnum
constants that defines the data type of the new
Field
.
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
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.
The optional
Attrib
parameter is one of the
FieldAttributeEnum
constants that specify the attributes of the new
Field
.
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
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.
Code (VBScript):
objRecord.Fields.
Append "Age", adInteger
CancelUpdate Method
Implemented in version 2.5
The
CancelUpdate
method cancels all pending deletions, insertions, or updates to the
Fields Collection
for a specific
Record
object. All existing
Field
objects are returned to the value they had after the last call of the
Update
method (if a call occurred). The status value is set to
adFieldOK
for all
Field
objects in the collection. This method has no parameters.
Code (VBScript):
objRecord.Fields.
CancelUpdate
Delete Method
The
Delete
method designates that a specified
Field
object is to be deleted from the
Fields Collection
. You must call the
Update
method of the
Fields Collection
to make this deletion.
Syntax:
Fields.
Delete
Index
This method has one parameter.
The
Index
parameter is either the name property or the ordinal position (index) in the collection of the
Field
object.
Code (VBScript):
objRecord.Fields.
Delete
3
Refresh Method
Although, the
Refresh
method is used to update objects in a collection, this method has no effect on the
Fields Collection
of the
Record
object.
Resync Method
Implemented in version 2.5
The
Resync
method is used to refetch the data from the underlying data source and to update (resynchronize) the values in the
OriginalValue
,
UnderlyingValue
, and
Value
properties of
Field
objects that are in the
Fields Collection
object of a
Record
object, or just to update the
UnderlyingValue
property. The effect of calling this method will depend on the value of the
Status
for each
Field
object. For example,
Field
objects with an
adFieldPendingUnknown
or
adFieldPendingInsert
status are not affected by calling this method.
This method has one optional parameter.
The optional
ResyncValues
parameter is one of the
ResyncEnum
constants that determines which values can be overwritten. The default is to update the
OriginalValue
,
UnderlyingValue
, and
Value
properties.
ResyncEnum Constants
Constant
Value
Description
adResyncAllValues
2
Default, can overwrite all values, and pending updates are cancelled
adResyncUnderlyingValues
1
Can only overwrite underlying values, and pending updates are not cancelled
Code (VBScript):
objRecord.Fields.
Resync
adResyncUnderlyingValues
Update Method
Implemented in version 2.5
The
Update
method is called to make additions, deletions, and updates to the
Fields Collection
of the
Record
object.
Code (VBScript):
objRecord.Fields.
Update
Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
Trademark Information