Using ADO VC++ Extensions

See Also   

Define Binding Entries

The ADO VC++ Extensions map the fields of a Recordset object to C/C++ variables. The definition of a mapping between a field and a variable is called a binding entry. Preprocessor macros are provided to define binding entries for numeric, fixed-length, and variable-length variables.

Bracket your binding entries between BEGIN_ADO_BINDING and END_ADO_BINDING macros. You should not terminate your binding entries by either commas or semicolons. These delimiters are specified for you within the macros.

Specify one binding entry for each field to be converted to a C/C++ variable. Use the appropriate ADO_FIXED_LENGTH_BINDING_ENTRY, ADO_NUMERIC_BINDING_ENTRY, or ADO_VARIABLE_LENGTH_BINDING_ENTRY macros.

In the parameters for the macros, the Recordset field to be extracted is specified by an ordinal number—zero identifies the first field, one identifies the second field, and so on.

The C/C++ variable is declared with a data type. If the variable is numeric, you can also specify precision and scale. If the variable is variable-length, like a string, you must specify the maximum size of the variable in bytes. The Recordset field value will be coerced to this data type if necessary.

Specify a temporary work buffer, which will be used to convert the field value from a VARIANT to a C/C++ variable. The buffer should be at least as large as the C/C++ variable.

Set the Boolean modify parameter to TRUE to enable ADO to update the bound field, and FALSE if you merely want to examine the field but not change it. The VC++ Extension doesn't maintain state information about a field, so you must specify whether ADO should change a field's value (for example, the value of an autoincrement field maintained by the data source). Therefore, the modify parameter for such a field should be set to FALSE.

The status parameter tells you whether the conversion from a Recordset field to a C or C++ variable was successful and whether the contents of the variable are valid. The  two most important values for this parameter are adFldOK, which means the conversion was successful; and adFldNull, which means the field was NULL—it had no value to convert.

Check this parameter first to determine if the C or C++ variable is valid. For example, if a field has valid contents for a row, status will be adFldOK. If you move to another row where the field is NULL, status will be adFldNull. However, the contents of the C or C++ variable will be unchanged—the variable will still contain the value of the field from the previous row.

Bind the Recordset to Variables

In your application, call the BindToRecordset interface method to associate (or bind) the Recordset fields to C/C++ variables. Your C/C++ variables will automatically be updated whenever the current row of the Recordset object changes.

Header Files

Include the following file in your application in order to use the VC++ Extensions:

Interface Methods

The IADORecordBinding interface has methods to associate Recordset fields with C/C++ variables, add new rows, and perform updates. All three methods take a pointer to a class derived from CADORecordBinding, which defines the binding between each field and variable.

The interface methods are:

Call this method to associate fields with variables.

Call this method to indirectly invoke the ADO AddNew method.

Call this method to indirectly invoke the ADO Update method.

Preprocessor macros

Parameter Description
cls Class where the binding entries, buffer, and Recordset object are defined.
Ordinal Ordinal field number; zero for the first field, one for the second, and so on.
DataType Data type of the variable where the converted field will be stored.
Buffer Buffer used to convert the field to a variable.
Status Indicates the success of the field conversion.
Modify A Boolean flag; if TRUE, indicates ADO can update the associated field.
Precision Number of digits that can be represented in the numeric variable.
Scale Number of decimal places in the numeric variable.
Size Number of bytes required for a variable-length variable, such as a string.

status Parameter Values Description
adFldOK A non-NULL field value was returned.
adFldBadAccessor Binding was invalid.
adFldCantConvertValue Value couldn't be converted for reasons other than sign mismatch or data overflow.
adFldNull A NULL was returned.
adFldTruncated Variable-length data or numeric digits were truncated.
adFldSignMismatch Value is signed and variable data type is unsigned.
adFldDataOverFlow Value is larger than could be stored in the variable data type.
adFldCantCreate Unknown column type and field already open.
adFldUnavailable Field value could not be determined—for example, on a new, unassigned field with no default value.
adFldPermissionDenied When updating, no permission to write data.
adFldIntegrityViolation When updating, field value would violate column integrity.
adFldSchemaViolation When updating, field value would violate column schema.
adFldBadStatus When updating, invalid status parameter.
adFldDefault When updating, a default value was used.