Locate

    AdoTable1.Locate('Name','Zoom',[]);

    var ffield, fvalue: string;

           opts : TLocateOptions;

    ffield := 'Name';

    fvalue := 'zoom';

    opts := [loCaseInsensitive]; 

    if not AdoTable1.Locate(ffield, fvalue, opts) then 

       ShowMessage(fvalue + ' not found in ' + ffield);

 

Lookup

Lookup does not move the cursor to the matching row, it only returns values from it.

var LookupRes: Variant;

LookupRes := ADOTable1.Lookup ('Name', 'Zoom', 'Author; Description');

 if not VarIsNull(LookupRes) then

ShowMessage(VarToStr(LookupRes[0])) //author name

Seek

The ADO datasets Seek method uses an index when performing a search.

You cannot use the Seek method on TADOQuery component.

  function Seek(const KeyValues: Variant; SeekOption: TSeekOption = soFirstEQ): Boolean;

  TSeekOption:   soFirstEQ,soLastEQ,soAfterEQ,soAfter,soBeforeEQ,soBefore

 

var strIndex: string;

strIndex := ComboBox1.Text; //from the code above

 

if ADOTable1.Supports(coSeek) the begin

  with ADOTable1 do begin

Close;

IndexName := strIndex;

CursorLocation := clUseServer;

Open;

Seek (Edit1.Text, soFirstEQ);

 end;

 if ADOTable1.EOF then

ShowMessage ('Record value NOT found');

 end

posted on 2012-12-13 20:17  许小东  阅读(290)  评论(0编辑  收藏  举报