1
votes

noob here. The question once again says it all, :).

I have a ADOTable that is connected to a dbgrid and .mdb file. I want to filter my table field "OwnerName" for all instances of a string that contain another substring and display them on the dbGrid. Each record has this string field "OwnerName". How do I do this?

Ex: substring: 'J' Strings: 'Jannie', Johanna, Ko-Ja etc..

If possible I also want to be able to filter for string that not only start with that exact wubstring, but contain it later in as well, as with my stupid example: Ko-Ja.

Regards!!!

1
Try to use a WHERE clause in you SQL statment using the LIKE keyword. Somthing like: SELECT * FROM MyTable WHERE (OwnerName LIKE "%J%") or (OwnerName LIKE "Fred%"). Of course you may combine many boolean expressions with and/or operators (and others). - fpiette
@fpiette Thx for the advice, but I am not allowed to use SQL, its for a school PAT. I was wondering if someone could help me understand the .filter method - Romans

1 Answers

3
votes

The are just two properties you have to set: Filter and Filtered. In the first set the filter condition (similar to SQL) and the second is a boolean stating whether to apply the filter or not.

Example:

YourADOTable.Filter := 'OwnerName LIKE ''%J%''';
YourADOTable.Filtered := True;

The %s in '%J%' means 'anything'.. so this way you are filtering for records which has in the OwnerName the text 'anything followed by a J and then anything again'.

Once you apply the filter, the dbGrid updates automatically.

You can find more info on Filter String at: http://docwiki.embarcadero.com/Libraries/Sydney/en/Data.DB.TDataSet.Filter