To link two fields from different tables in DBGrid

Discussion of open issues, suggestions and bugs regarding PgDAC (PostgreSQL Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
piopio
Posts: 17
Joined: Tue 22 Nov 2011 23:41

To link two fields from different tables in DBGrid

Post by piopio » Tue 22 Nov 2011 23:48

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

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Post by AlexP » Thu 24 Nov 2011 08:59

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

piopio
Posts: 17
Joined: Tue 22 Nov 2011 23:41

Post by piopio » Thu 24 Nov 2011 10:14

Thank you for your help, Alex

:D

Post Reply