楼上说的我没有用过,我自己有种笨法子,你可以试一下begin datasource1.close; adotable1.first; while not adotable.eof do begin if adotable['ziduan']=' 你查询的记录' then break else adotable.next; end; datasource1.open;
用adoquery.sql, 和 datasource 链接几下就行了,
如果查询条件很简单可用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.
adotable.Locate('ziduan',' 你查询的记录' ,[]);
adotable.Locate.不过只能显示一条记录,如果你查出的有2条以上就不太好了.
ADOQuery1.Close; ADOQuery1.SQL.Clear; ADOQuery1.SQL.Add('select * from TableName '); ADOQuery1.Open;
用adodataset呀! adodataset.commandtext:='select * from ff where hhh=''dddd'''; adodataset.open;
datasource1.close;
adotable1.first;
while not adotable.eof do
begin
if adotable['ziduan']=' 你查询的记录' then break
else adotable.next;
end;
datasource1.open;
原文:
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.
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('select * from TableName ');
ADOQuery1.Open;
adodataset.commandtext:='select * from ff where hhh=''dddd''';
adodataset.open;
VarArrayOf(['Sight Diver', 'P', '408-431-1000']):各个字段值
[loPartialKey]):参数,比如不区分大小写等
不建议使用adotable(特别是表数据记录量大而要查询的数据集又少,浪费资源)
,用adotable,adoquery,adodataset都可以,因为都继承自tdataset。