Page 1 of 1

To link two fields from different tables in DBGrid

Posted: Tue 22 Nov 2011 23:48
by piopio
Hello,


Sorry if I post very basic questions but I am moving the first steps in client/server programming.

I have two tables the fist called "customers" with a numeric field "userID" in it; a second table called pgusers with a numeric field "userID" and a varchar field called "name".

What I want to achieve is to link the two tables together in a dbgrid and show the user name designated to each customer instead of userID.

In order to do so I placed two pgtables (one for customers and the other users) and linked to the relevant pgdatasources.

I opened the fields editor of customers and added a few fields including customers.userID. Then I populated the following properties of userID:
- lookupdataset=pgusers
- lookupkeyfields=userID
- lookupresultfields=name

then compiled but I can't see the username replacing its ID.

Is there anything else I have to do ?


Many thanks


Pio Pio

Posted: Thu 24 Nov 2011 08:59
by AlexP
Hello,

If you want to display contents of several tables in one DBGrid, you need to join these tables in one query by joining them by key fields and specify fields to display:

SELECT c.*, p.*
FROM customers c, pgusers p
WHERE c.userID=p.userID

Posted: Thu 24 Nov 2011 10:14
by piopio
Thank you for your help, Alex

:D