We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Delphi - Database filter

Sebastion
Sebastion asked
on
Medium Priority
674 Views
Last Modified: 2012-05-05
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.
Comment
Watch Question

Commented:
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....

Commented:
You could also set a master detail relationship between the two tables, this is probably a better way to do it.

Author

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?
Commented:
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...)

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

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.

Commented:
The index does not have to be unique. Can be a "normal index"

Author

Commented:
According to what I've got, the only option under "available indexes" is "primary".

Commented:
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)

Author

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

Commented:
Thanks.
Glad I could help.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.