RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TCustomADODataSet.Seek Method

Searches for a record using the current index.

Pascal
function Seek(const KeyValues: Variant; SeekOption: TSeekOption = soFirstEQ): Boolean;
C++
__fastcall Boolean Seek(const Variant KeyValues, TSeekOption SeekOption = soFirstEQ);

Call Seek to find a record with a specified value (or values) in the field (or fields) on which the current index is based. An index must be active to use Seek. The field used for the search is that of the currently active index. Seek moved the record pointer of the dataset based on the success of the search. If the search finds a record, the record pointer is moved to that record. If Seek does not find a record matching the value in KeyValues using the comparison method specified in SeekOption, the record pointer is positioned to the end of the dataset. Seek returns a boolean value reflecting the success of the search: true if a record was found or false if no record was found.

SuccessVar := ADODataSet1.Seek('Jones', soFirstEQ);

 

SuccessVar = ADODataSet1->Seek("Jones", soFirstEQ);

If the current index is based on more than one field, search values supplied in the Seek method must be for all fields sequentially from left to right in the index expression. That is, if the index is based on three fields, the search can be on the first field, the first and second fields, or on the first and second and third fields. It cannot be based only on the third field or on a combination of the first and third fields. To execute a search based on multiple fields, pass a variant array to the Seek method. 

KeyValues is the value to search for or multiple values if the index is based on multiple fields.

ADODataSet1.Seek(VarArrayOf([90030, 90020]), soFirstEQ);

 

ADODataSet1->Seek(VarArrayOf(OPENARRAY(Variant, (90030, 90020))), soFirstEQ);

SeekOption specifies the type of comparison made in determining whether the search was successful. SeekOption can be one of the six constants:

Seek Option 
Meaning 
soFirstEQ  
Record pointer positioned at the first matching record, if one is found, or at the end of the dataset if one is not found.  
soLastEQ  
Record pointer positioned at the last matching record, if one is found, or at the end of the dataset if one is not found.  
soAfterEQ  
Record pointer positioned at matching record, if found, or just after where that matching record would have been found.  
soAfter  
Record pointer positioned just after where a matching record would have been found.  
soBeforeEQ  
Record pointer positioned at matching record, if found, or just before where that matching record would have been found.  
soBefore  
Record pointer positioned just before where a matching record would have been found.  

Using the Seek method depends on the settings of a few properties. IndexName must be set to activate the index to use, CommandType must be cmdTableDirect (for TADODataSet, set TableDirect to true for a TADOTable), CursorLocation must be clUseServer, and CursorType must be ctKeySet.

Note: The VCL Seek method is a direct implementation of the Seek method for the ADO Recordset object. At the time of this writing, this method is only supported for use with Microsoft Access2000 and the Jet 4 provider.
 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!