我用的是adoconnection与SQL数据库进行连接,用dbgrid来显示数据,现在想对其中的记录进行查询,只要能让dbgrid的记录位置显示是要查询的记录的当前位置即可。不知道怎么做,请教各位高手!谢谢了!

解决方案 »

  1.   

    试一下adotable1.locate()这个过程,应该可以满足你的要求
      

  2.   

    楼上说的我没有用过,我自己有种笨法子,你可以试一下begin
       datasource1.close;
       adotable1.first;
       while not adotable.eof do
         begin
           if adotable['ziduan']=' 你查询的记录' then break 
           else adotable.next;
         end;
       datasource1.open;
      

  3.   

    用adoquery.sql, 和 datasource 链接几下就行了,
      

  4.   

    如果查询条件很简单可用Locate方法,找到会将其置为当前记录
    原文:
    earches the dataset for a specified record and makes that record the current record.
    Delphi syntax:function Locate(const KeyFields: String; const KeyValues: Variant; Options: TLocateOptions
    ): Boolean; override;DescriptionCall Locate to search a dataset for a specific row and make it the current row.KeyFields is a string containing a semicolon-delimited list of field names on which to search.KeyValues is a variant that specifies the values to match in the key fields. If KeyFields lists a single field, KeyValues specifies the value for that field on the desired row. To specify multiple search values, pass a variant array as KeyValues, or construct a variant array on the fly using the VarArrayOf routine. For example:
    下面是个例子:
    with ADOTable1 do
      Locate('Company;Contact;Phone', VarArrayOf(['Sight Diver', 'P', '408-431-1000']), [loPartialKey]);

    Options is a set that optionally specifies additional search latitude when searching on string fields. If Options contains the loCaseInsensitive setting, then Locate ignores case when matching fields. If Options contains the loPartialKey setting, then Locate allows partial-string matching on strings in KeyValues. If Options is an empty set, or if KeyFields does not include any string fields, Options is ignored.Locate returns true if it finds a matching row, and makes that row the current one. Otherwise Locate returns false.
      

  5.   

    adotable.Locate('ziduan',' 你查询的记录' ,[]);
      

  6.   

    adotable.Locate.不过只能显示一条记录,如果你查出的有2条以上就不太好了.
      

  7.   

    ADOQuery1.Close;
    ADOQuery1.SQL.Clear;
    ADOQuery1.SQL.Add('select * from TableName ');
    ADOQuery1.Open;
      

  8.   

    用adodataset呀!
    adodataset.commandtext:='select * from ff where hhh=''dddd''';
    adodataset.open;
      

  9.   

    Locate('Company;Contact;Phone', VarArrayOf(['Sight Diver', 'P', '408-431-1000']), [loPartialKey]);'Company;Contact;Phone':要查找字段,可以多个,用;号分开
    VarArrayOf(['Sight Diver', 'P', '408-431-1000']):各个字段值
    [loPartialKey]):参数,比如不区分大小写等
      

  10.   

    同意楼上.
    不建议使用adotable(特别是表数据记录量大而要查询的数据集又少,浪费资源)
      

  11.   

    up
    ,用adotable,adoquery,adodataset都可以,因为都继承自tdataset。