Freigeben über


CDaoRecordset::SetCurrentIndex

Call this member function to set an index on a table-type recordset.

void SetCurrentIndex(
   LPCTSTR lpszIndex 
);

Parameters

  • lpszIndex
    A pointer containing the name of the index to be set.

Remarks

Records in base tables are not stored in any particular order. Setting an index changes the order of records returned from the database, but it does not affect the order in which the records are stored. The specified index must already be defined. If you try to use an index object that does not exist, or if the index is not set when you call Seek, MFC throws an exception.

You can create a new index for the table by calling CDaoTableDef::CreateIndex and appending the new index to the Indexes collection of the underlying tabledef by calling CDaoTableDef::Append, and then reopening the recordset.

Records returned from a table-type recordset can be ordered only by the indexes defined for the underlying tabledef. To sort records in some other order, you can open a dynaset-type or snapshot-type recordset using a SQL ORDER BY clause stored in CDaoRecordset::m_strSort.

For related information, see the topic "Index Object" and the definition "current index" in DAO Help.

Requirements

Header: afxdao.h

See Also

Reference

CDaoRecordset Class

Hierarchy Chart

CDaoRecordset::GetCurrentIndex

Other Resources

CDaoRecordset Members