Board index » delphi » Filtering table already filtered .....

Filtering table already filtered .....

Hi ,
     j have one problem ......
J have one table with 5003 records and there is a button that open a filter
form.
In this form there are :
#1 TQuery                 (Query1)
#1 TDBGrid              (DBGrid1)
#1 TDataSource      (DataSource1)

DBGrid1 is linked to DataSource1 and DataSource1 is linked to Query1

Now j filter the table with the Query1.Sql and the line is :

Query1.SQL.Add('Select * FROM '+TT.TableName+' WHERE Brand' Like '
+QuotedStr(FilterEdit.Text));

Where :
TT.TableName is the table name (MyTable.DB)
Brand                is one record's field
FilterEdit           is the TEdit component (the value is 'band%')

When j run the query j will find about 1000 record ( given by
Qurey1.RecordCount ).
At this point j need to refilter the query ..... but how is possible ??????

If j try to do this

Query1.SQL.Add('Select * FROM Query1  WHERE Brand' Like '
+QuotedStr(FilterEdit.Text));

when j run the query j will get this error
File or directory does not exist :
C:\......\.....\Query1.DB
C:\.......\.....\Query1.DBF
C:\........\.....\Query1.TXT

What j can do to refilter this table ???

Thanks for your help

Bye

Daniele

 

Re:Filtering table already filtered .....


Hi!
Quote

> Where :
> TT.TableName is the table name (MyTable.DB)
> Brand                is one record's field
> FilterEdit           is the TEdit component (the value is 'band%')

> When j run the query j will find about 1000 record ( given by
> Qurey1.RecordCount ).
> At this point j need to refilter the query ..... but how is possible

??????
Just close and open your Query:
Query1.Close;
Query1.Open;
Quote

> If j try to do this

> Query1.SQL.Add('Select * FROM Query1  WHERE Brand' Like '

                                                   ^^^^^ Only table name can
be here!
SQL doesn't know anything about TQuery Query1 and looks for table with name
query1!

Quote
> +QuotedStr(FilterEdit.Text));

> when j run the query j will get this error
> File or directory does not exist :
> C:\......\.....\Query1.DB
> C:\.......\.....\Query1.DBF
> C:\........\.....\Query1.TXT

--
Best Regards
Yuri S. Levashko, LANIT Inc.

Re:Filtering table already filtered .....


Quote
On Thu, 18 Nov 1999 09:29:46 +0100, "Daniele" <x...@xxx.xxx> wrote:

[...]

Quote
>If j try to do this

>Query1.SQL.Add('Select * FROM Query1  WHERE Brand' Like '
>+QuotedStr(FilterEdit.Text));

>when j run the query j will get this error
>File or directory does not exist :
>C:\......\.....\Query1.DB
>C:\.......\.....\Query1.DBF
>C:\........\.....\Query1.TXT

>What j can do to refilter this table ???

That TQuery component Query1 is a Delphi object, existing only in the
Delphi application's memory space. SQL, OTOH, can only be executed against
persistent base tables. You cannot reference a TQuery or TTable in an SQL
statement as if it were a base table.

One option you have is to add the new criteria to the existing SQL
statement and execute it again.

Another option is to save the result set to a (local) base table using the
BDE API function DbiMakePermanent. Then, you can execute the second SELECT
statement against that new table.

If the original statement is executed against a local table (dBASE,
Paradox, FoxPro), you can use the local SQL equivalent of a VIEW. Save the
first statement to a text file (with a .SQL extension) and execute the
second statement against that file. This is more akin to the first choice,
above, as the first query ends up being executed again.

If the SQL is on an SQL database, you can use a VIEW based on the first
statement to derive the second result set.

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
Steve Koterski              "Health nuts are going to feel stupid someday,
Felton, CA                  lying in hospitals dying of nothing."
                                                              -- Redd Foxx

Other Threads