CreateField Method

See Also      Applies To

Creates a new CdbField object (Microsoft Jet workspaces only).

Syntax

CdbFieldCreateField(LPCTSTR pstrName = NULL,

LONG lType = -1,

LONG lSize = -1);

Parameters

Type Example Description
LPCTSTR pstrName

= NULL

Optional. A pointer to a string that uniquely names the new CdbField object. See the Name property for details on valid CdbField names.
LONG lType = -1 Optional. An integer that determines the data type of the new CdbField object. See the Type property for valid data types.
LONG lSize = -1 Optional. An integer that indicates the maximum size, in bytes, of a CdbField object that contains text. See the Size property for valid size values. This argument is ignored for numeric and fixed-width fields.

Remarks

You can use the CreateField method to create a new field, as well as specify the name, data type, and size of the field. If you omit one or more of the optional parts when you use CreateField, you can use an appropriate assignment statement to set or reset the corresponding property before you append the new object to a collection. After you append the new object, you can alter some but not all of its property settings. See the individual property topics for more details.

The lType and lSize arguments apply only to CdbField objects in a CdbTableDef object. These arguments are ignored when a CdbField object is associated with a CdbIndex or CdbRelation object.

If pstrName refers to an object that is already a member of the collection, a run-time error occurs when you use the Append method.

To remove a CdbField object from a Fields collection, use the Delete method on the collection. You can't delete a CdbField object from a CdbTableDef object's Fields collection after you create an index that references the field.

Usage

#include <afxole.h>
#include <dbdao.h>

CdbTableDef   td;
...
td.CreateField(_T("CarModel"), dbText, 30);