Please, please help.

I have a curriculum theme - a video rental program, there are 2 labels, in the 1st label there will be genres, I think so, and in the 2nd title of the film, the genre, who took from what date, what date, was rented or not.

How can I link two tables by what keys so that the genre can be selected in the 1st table, and in the 2nd table all the films of this genre would be knocked out.

I hope for your help. =)

    2 answers 2

    I think this: the first table (main): ID (key), the name of the film, genre (number), etc., and another table genre, where ID (key) and the name of the genre. In the field of the main table genre, you need to write the ID of the genre and create a substitution field in it so that the name of the genre is displayed, not its number. Tables in Delphi are linked using the MasterSource property of the components (Table, ADOTable), and the field of the main table (the field by which to link) is the property of the MasterField. If the version of Delphi 7, then there can be easier: through the data scheme (diagram). By the way, I almost forgot, it is not always possible to make connection fields in Delphi wildcard. So you have to decide what you need. It seems to me that I need to create a Lookup Field in the Table data set. Selection by genre can be done using filtering or SQL query.

    • ATP for help ... but filtering through what to do better? and how to make a wildcard) if you can describe it) - Pavel Borschev
    • Select a table (Table), click the right mouse button and select Add All Fields ... (if there are no all fields), and add a New Field, select the Lookup Field type there, name the field (specify the Field Name), specify the type (in this case, string ), select the data source of the lookup (Lookup Data), keyFields - field - genre number, LookupKeyFields field ID of the genre, ResultField - field the name of the genre (in your case). You can read more on the Intuit section http //: www.intuit.ru: there the course is "Database programming in Delphi". - DelphiM0ZG

    Dear @ DelphiM0ZG and I did not understand what you mean: the interface of your program or the schema of the tables in the database.

    Scheme of tables 1) reference table (parent) GENRE: genre ID, Title. 2) A business table (child) with movie names must contain a foreign key that indicates the ID_genre of the first table.

    Interface: everything, as respected @ DelphiM0ZG writes , with the replacement of the word "table", for example, with "DBGrid".

    • ATP guys) helped if it’s not clear I will know where to run) - Pavel Borschev
    • I meant a data set (Table), but not an interface. - DelphiM0ZG