Using LIKE statement for filtering

后端 未结 6 1726
南方客
南方客 2021-01-05 06:44

Im using this code to filter my table:

Table.Filtered := False;
Table.Filter := \'[\' + Field_Search + \'] LIKE \'\'%\' + Edit_Search.Text + \'%\'\'\';
Tabl         


        
6条回答
  •  不知归路
    2021-01-05 07:33

    A TTable.Filter isn't a SQL query. LIKE isn't supported (neither is IN). The supported operators are =, <>, >, <, >=, '<=,AND,NOTandOR`, according to the documentation

    For more complicated filtering, use the TDataSet.OnFilterRecord event:

    procedure TForm1.Table1FilterRecord(Dataset: TDataset; var Accept: Boolean);
    begin
      // Don't remember if D7 supports DataSet[FieldName] syntax; if not,
      // use DataSet.FieldByName instead, or a persistent field.
      Accept := Pos(Edit_Search.Text, DataSet[SearchField].AsString) > 0;
    end;
    

提交回复
热议问题