Re: TADODataset.Filter?



Thanks for your efforts, I shall be doing more tests later today,
and in the meantime:

1: I should be most surprised if there is anything wrong in the
connections between Dataset, Datasource and DBGrid. After
all I have the correct results when I do not use the filter property?
They are connected as much as possible already at compile-
time (I shall triple-check this though). Also my filter attempts
worked as expected, but only for exact matches when I used
equal sign instead of the word LIKE (and wildcards probably
treated as significant characters even though the filteroptions
property is empty).

2: Is there a typo in your text below? Shouldn't the parameter to
QuotedStr be (edit1.Text + '*') ?

3: I noticed that you seemed to use the Filter and Filtered
properties either or both in TADODataset and in TADOQuery.

I see no need to involve TADOQuery so all my filtering attempts
are done on my TADODataset component. Do you know if there
could be any trap here? (I have TADOConnection, TADODataset,
TDataSource and TDBGrid all linked together and working
as expected except for my difficulties with local filtering).

regards Sven

"Bill Dekleris" <quasar@xxxxxx> wrote in message
news:453b399a@xxxxxxxxxxxxxxxxxxxxxxxxx
Sven,

are you sure your DBGrid is connected to the correct DataSource / DataSet?
I know it's a stupid remark, but sometimes we overlook such details when
engaging in furious testing...

The code I sent you works for me. To be exact, here is the event handler
for the "filter" button click:

procedure TForm1.Button2Click(Sender: TObject);
begin
// ADOQuery1.Filtered := false;
ADOQuery1.Filter := 'name like ' + QuotedStr(edit1.Text);
ADOQuery1.Filtered := true;
end;

Notice that I don't even need to enable "ADOQuery1.Filtered := false". It
works either way.

Also, after Googling a bit, I came across the following (older) post:
http://groups.google.gr/group/comp.lang.pascal.delphi.databases/browse_thread/thread/6e11209f42079578/511e3467a8adfafc%23511e3467a8adfafc
where I found out that the wildcard characters depend on the version of
the Jet driver you use. Some versions support * and ?, others % and _.
So I tested it, and realized that BOTH * and % wildcards work (using
Microsoft.Jet.OLEDB.4.0 provider)!

Please let me know if you made any progress.

Regards,

Bill Dekleris.

-----------------------------------------------------------------------------------------


http://www.infosnap.eu

InfoSnap · the powerful, all-purpose information and knowledge-base
manager.

-----------------------------------------------------------------------------------------


Sven Pran wrote:
"Bill Dekleris" <quasar@xxxxxx> wrote in message
news:453a4e00@xxxxxxxxxxxxxxxxxxxxxxxxx
Oops! I forgot to quote the search string! The correct syntax would be:

// name starts from "bi"
ADOQuery1.Filter := 'name Like ' + QuotedStr('bi*');

// name contains "bi"
ADOQuery1.Filter := 'name Like ' + QuotedStr('*bi*');

Sorry for the error!

Bill.


I tried this tonight and got a most surprising result:

No error message and no filtering?

I single-stepped the application and could see that
ADODataset1 was "loaded" with a separate SQL SELECT
statement. Then whenever I changed the filter mask
(in an edit box) I could see that the following statements
were executed

1: ADODataset1.Filtered := false;
(typically) 2: ADODataset1.Filter := 'name LIKE ' + QuotedStr('bi*');
3: ADODataset1.Filtered := true;

but the DBGrid display did not change, it still displayed
the entire dataset?

Now I am lost? (It is 2:15 AM here and I am going to bed.)

regards Sven



.


Quantcast