开发者

Need help with Delphi and ADOTable filtering

开发者 https://www.devze.com 2023-03-22 15:14 出处:网络
i m trying to build an invoice program that holds data in an Access db. i have some tedit s, buttons, one datasource, one adotable, one dbgrid and a popup menu. database format is accdb.

i m trying to build an invoice program that holds data in an Access db. i have some tedit s, buttons, one datasource, one adotable, one dbgrid and a popup menu. database format is accdb.

Problem: i want the program to filter records while user is typing. it might filter dbgrid or tedit, doesn t matter. i somehow found some code, for example:

Table1.开发者_如何学编程FilterOptions:=[foCaseInsensitive];
Table1.Filter:='Filmadi='+QuotedStr(Edit1.Text+'*');
Table1.Filtered:=true;

the code above gives this error: Project Project1.exe raised exception class eoleexception with message: Item cannot be found in the collection corresponding to the requested name or ordinal

other examples give various errors.

sincerely

onur


Use LIKE operator in your filter:

procedure DoIncrementalFilter(Dataset: TDataSet; const FieldName, SearchTerm: string);
begin
  Assert(Assigned(Dataset), 'No dataset is assigned');

  if SearchTerm = '' then
    Dataset.Filtered := False
  else
  begin
    Dataset.Filter := FieldName + ' LIKE ' + QuotedStr(SearchTerm + '*');
    Dataset.Filtered := True;
  end;
end;

Example:

  DoIncrementalFilter(ADOTable1, 'Filmadi', Edit1.Text);
0

精彩评论

暂无评论...
验证码 换一张
取 消