• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 359
  • Last Modified:

Delphi - Database filter

Hello,

I have a customer form that grabs information from a paradox table called "customer".  This form also has a data grid that lists all the items that the customer has purchased, which is stored in another paradox tabled called "sales".

What I want to do is filter the data grid by customer name, so that when the user navigates through each customer, only their sale information is displayed in the datagrid.

The data grid is linked to a different table object on the form.  I've tried to apply a filter to the datagrid already, using:

SalesTable.Filter := '[Customer Name] = ' + '[' + CustomerTable.FieldByName('Customer Name').Value + ']';


But this results in an error.


It feels like I'm missing something very minor.
0
Sebastion
Asked:
Sebastion
  • 6
  • 4
1 Solution
 
RickJCommented:
I would think that your filter need to be like follows...

SalesTable.Filter := 'Customer Name = ' + '''' + CustomerTable.FieldByName('Customer Name').Value + '''' ;
Assuming Customer name is a string.

I also would have thought that you can not have a space in the field name, is it really Customer_Name maybe....

0
 
RickJCommented:
You could also set a master detail relationship between the two tables, this is probably a better way to do it.
0
 
SebastionAuthor Commented:
There is a space, in the field "Customer Name" in the paradox database.  Personally, I'd probably have put CustomerName, but I'm actually building off a previous setup here.

The field is indeed a string, but if I take away the square brackets [], then the compiler doesn't interpret the full field name.

For example, in the above code you've written, the following error results:

SalesTable: Field 'Customer' not found.  Process Stopped.  Use Step or Run to continue.


However, if I put square brackets around the words "Customer Name", the compiler can now interpret the entire string, and finds the field fine.



I could try a master detail relationship, could you give me the gist of what I would have to do to accomplish this?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
RickJCommented:
Sorry about that, sort of assumed that Customer Name was incorrect.
For the Master Detail.....
On the Sales table you need to set the MasterSource property to a datasource component that points to the Customer Table.
Then set the Masterfields property on the Sales table to the master field in the Customer table i.e Customer Name.
The Sales table also has to be indexed to the Customer Name Field.
The sales table will then only show the records for the Customer Name that match the master table.

I hope that makes sense....
How is the weather in Queensland, it is freezing in Victoria. (Unusual...)
0
 
SebastionAuthor Commented:
Hmm, from the looks of things it's going to use the primary key of the sales table, which is SalesID.  This actually cannot be linked to anything in the Customer table, since it's only used to uniquely identify each individual sales record.

Since the link appears to require a primary key on the SalesTable part, then I wouldn't be able to simply make the "Customer Name" field in the sales table a primary key, as it's not unique (A Customer could have many different sales).

Any thoughts?


P.S, it's actually quite warm up here in Queensland, though it's been threatening to storm for the last couple of days.
0
 
RickJCommented:
The index does not have to be unique. Can be a "normal index"
0
 
SebastionAuthor Commented:
According to what I've got, the only option under "available indexes" is "primary".
0
 
RickJCommented:
You would need to create an index on the Customer Name field.
I dont think even using the indexfieldnames property is an option, because I think paradox still requires it to be indexed. (Havent used paradox for a while)
0
 
SebastionAuthor Commented:
Yep, you're right.  I set up the customer name field as an index through the paradox database management program and it's now an option in the master-detail relationship.  Things look to be working alright, with the few meager test entries that I've entered in.

Thanks for the help
0
 
RickJCommented:
Thanks.
Glad I could help.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now