Re: TADODataset.Filter?



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