Article ID: 149087
Article Last Modified on 11/21/2006
BOOL Seek( LPCTSTR lpszComparison,
COleVariant* pKey1,
COleVariant* pKey2 = NULL,
COleVariant* pKey3 = NULL );
BOOL Seek (LPCTSTR lpszComparison,
COleVariant* pKeyArray,
WORD nKeys );
When you call Seek, you pass one or more key values and a comparison
operator (<, <=, =, >=, or >). Seek searches through the current
index and locates the first record that satisfies the criteria specified by
lpszComparison and the key values passed to it. Once found, Seek returns a
nonzero value and makes that record current. If Seek fails to locate a match,
Seek returns zero and the current record is undefined.
// Using the first version of Seek specifying the
// first field in the index:
void CMyDaoRecordset::FindCourse()
{
m_pSet->SetCurrentIndex( _T("PrimaryKey") );
COleVariant varCourse ( _T("MATH202"), VT_BSTRT );
if( m_pSet->Seek( _T( "=" ), &varCourse ) )
// then you have found the record and it is now
// the current record
// Using the first version of Seek specifying the
// first two fields in the index:
void CMyDaoRecordset::FindCourse()
{
m_pSet->SetCurrentIndex( _T("PrimaryKey") );
COleVariant varCourse ( _T("MATH202"), VT_BSTRT );
COleVariant varSection( _T( "2" ), VT_BSTRT );
if( m_pSet->Seek( _T( "=" ), &varCourse, &varSection ) )
// then you have found the record and it is now
// the current record
The first version of Seek may be used with up to three fields. If an
index has more than three fields and you need to specify more than three
fields, use the second version of Seek. An array of COleVariants will be
passed.
// Using the second version of Seek, specifying the first four
// fields of the index:
void CMyDaoRecordset::FindCourse()
{
m_pSet->SetCurrentIndex( _T("Secondary") );
COleVariant varCourse ( _T( "MATH202" ), VT_BSTRT );
COleVariant varSection ( _T( "2" ), VT_BSTRT );
COleVariant varInstructor( _T( "ROGERSN" ), VT_BSTRT );
COleVariant varRoomNo ( _T( "KEN-12" ), VT_BSTRT );
// Now create an array and let the assignment
// operator of COleVariant populate the array
COleVariant rgVariant[4];
rgVariant[0] = varCourse;
rgVariant[1] = varSection;
rgVariant[2] = varInstructor;
rgVariant[3] = varRoomNo;
if( m_pSet->Seek( _T( "=" ), &rgVariant[0], 4 ) )
// then you have found the record and it is now
// the current record
140599 MFC DAO functions accepting COleVariant strings may fail
140599 PRB: MFC DAO Functions Accepting COleVariant Strings May Fail
Keywords: kbfunctions kbinfo kbcode kbdatabase kbhowto KB149087