The master-slave composite structure (Master/detail) is based on "one-to-many" relationships, providing detailed information in a database table that accesses related records through foreign keywords from another database table. Based on the master-slave composite structure, we can browse the data in one table and give all the record information related to the record in another table. Borland C++builder provides a ttable and tquery type of database control that can easily implement the Master/detail relationship of database tables, In this paper, we take the example database Bcdemos in BCB as an example to illustrate how to implement the master-slave composite structure relationship of the data table by different methods, Take the data browsing function as an example: When browsing the Master Datasheet customer.db (Customer information) record, display the details of all records associated with it from the datasheet orders.db (Customer order information).
The basic properties related to the Ttable control are described below: DatabaseName: Set the database alias or database directory path to open; TableName: Set the file name of the database table you want to associate open, Active: The database table file opens automatically when set to true. Otherwise, you need to open the data table in your program with code. Tquery control's basic properties: DatabaseName: Sets the database alias or database directory path to open; The sql:tstring type, the SQL data query statement to execute, can be directly in the object viewer Inspector) Double hit Open SQL property for editing, Active: When set to true automatically open query database table file, otherwise you need to use code to open the query datasheet in the program. The properties associated with M/D will be explained in conjunction with the example below.
One, Ttable Control Association master, Implementation master/detail Relationship report from table
The simplest way to implement a master/detail relationship is to associate two Ttable controls with the primary table and from the table, respectively. Named Tablemaster and Tabledetail respectively, set tablemaster databasename as Bcdemos, TableName is customer.db; the databasename for Tablemaster is bcdemos,tablename for orders.db. So you can correlate the master and subordinate data tables separately.