Article ID: 149087 - Last Review: November 21, 2006 - Revision: 3.1 How to use CDaoRecordset::Seek in Visual C++This article was previously published under Q149087 On This PageSUMMARY This article explains how to use CDaoRecordset::Seek. Seek
enables high- performance indexed searching on table-type recordsets. You can
call Seek to find the first record that satisfies the specified criteria for
the current index and make that record the current record. There are two
versions of the Seek member function that you can use to locate a record in an
indexed table-type recordset object. This article explains both. MORE INFORMATION There are two versions of Seek, one works with indexes that
are comprised of up to three fields and the other handles indexes comprised of
more than three fields. You must set the current index by calling
SetCurrentIndex before calling Seek. If you do not, an exception will be
thrown, as MFC does not specify a default index when a recordset is opened. If
the index identifies a non-unique key, Seek locates the first record that
satisfies the criteria. NOTE: If you are not creating a UNICODE recordset, any character string COleVariant objects must be explicitly declared ANSI. This can be done by using the COleVariant::COleVariant( lpszSrc, vtSrc ) form of constructor with vtSrc set to VT_BSTRT (ANSI) or by using the COleVariant function SetString( lpszSrc, vtSrc ) with vtSrc set to VT_BSTRT. SetString() is only available in MFC Version 4.1 or later. Here are the declarations for Seek: If the current index is a multiple-field index, then the key values for Seek must be in the same order as the fields in the index. In this case, trailing key values can be omitted. You can leave off any number of key values from the end of the list of key values but not from the beginning or middle. If you do choose to leave off trailing key values, Microsoft recommends that you use the >= operator instead of the = operator. The missing key values will be treated as NULL, which probably won't match the values in your table. NOTE: The Microsoft Jet database engine, and therefore the Seek method, does not perform case-sensitive searches. The easiest way to create an index object is from within Microsoft Access. Steps to Create an Index Object
Sample CodeREFERENCES
For more information, click the following article number to view the article in the Microsoft Knowledge Base:
140599
(http://support.microsoft.com/kb/140599/
)
MFC DAO functions accepting COleVariant strings may fail
For more information, please see the following article in
the Microsoft Knowledge Base: 140599
(http://support.microsoft.com/kb/140599/EN-US/
)
PRB: MFC DAO Functions Accepting COleVariant Strings May Fail
APPLIES TO
| Article Translations
|
Back to the top
