共用方式為


CDaoRecordset::GetFieldValue

Call this member function to retrieve data in a recordset.

virtual void GetFieldValue(
   LPCTSTR lpszName,
   COleVariant& varValue 
);
virtual void GetFieldValue(
   int nIndex,
   COleVariant& varValue 
);
virtual COleVariant GetFieldValue(
   LPCTSTR lpszName 
);
virtual COleVariant GetFieldValue(
   int nIndex 
);

Parameters

  • lpszName
    A pointer to a string that contains the name of a field.

  • varValue
    A reference to a COleVariant object that will store the value of a field.

  • nIndex
    A zero-based index of the field in the recordset's Fields collection, for lookup by index.

Return Value

The two versions of GetFieldValue that return a value return a COleVariant object that contains the value of a field.

Remarks

You can look up a field by name or by ordinal position.

注意

It is more efficient to call one of the versions of this member function that takes a COleVariant object reference as a parameter, rather than calling a version that returns a COleVariant object. The latter versions of this function are kept for backward compatibility.

Use GetFieldValue and SetFieldValue to dynamically bind fields at run time rather than statically binding columns using the DoFieldExchange mechanism.

GetFieldValue and the DoFieldExchange mechanism can be combined to improve performance. For example, use GetFieldValue to retrieve a value that you need only on demand, and assign that call to a "More Information" button in the interface.

For related information, see the topics "Field Object" and "Value Property" in DAO Help.

Requirements

Header: afxdao.h

See Also

Concepts

CDaoRecordset Class

CDaoRecordset Members

Hierarchy Chart

CDaoRecordset::SetFieldValue