Main / list table
nxyc_twz@163.com
The main / tomographic table between two tables is very wide. Therefore, it is very important to provide a simple method for database application developers. Let us see how to achieve this function. If we establish a master / chain table relationship between "Department" and "Employee". The "Department" table contains the following fields: DEPNO, DEPNAME, and LOCATION. DEPNO is a digital primary key, and the other two fields are string types. The "Employee" table contains the following fields: Empno, Empname, Job, Manager, and Depno. Empno and DEPNO are digital fields, EmpName and Job are string fields. Empno is a primary key and DEPNO is an foreign key that binds "Employee" and "Department". This is necessary to display and edit the data table. ODAC provides two methods of binding data sheets. The first code example shows that two ToraDataSet components (ToraQuery, TsmartQuery, Toratable, or TorastoredProc) are bound by parameters to the main / tomorrow relationship. procedure TForm1.Form1Create (Sender: TObject); varMaster, Detail: TOraQuery; MasterSource: TDataSource; begin // create a master data set Master: = TOraQuery.Create (Self); Master.SQL.Text: = 'SELECT * FROM Department' ; // Create a detail data set Detail: = ToraQuery.create (Self); detail.sql.text: = 'select * from Employee Where DepNo =: DepNo'; // The primary table is connected to the TDataSource component to connect the schedule MASTERSOURCE: = TDataSource.create (self); Mastersource.DataSet: = Master; detail.masterSource: = MASTERSOURCE; / / Open the master.open; detail.open; end; note one thing: Detail data set The parameter name in the SQL statement must be equal to the field name used as the foreign key foreign key in the main data set. After opening the schedule data set, its data is always equal to the value defined by the current primary data set record field (such as DEPNO). There is an additional function: When you insert a new record to the schedule dataset, it automatically obtains the value of the corresponding value from the homekend to fill the value of its foreign key. Now, if the foreign key "Department" is named deplink instead of deplno. In this case, the above code example is when the record is inserted, the schedule dataset will not automatically fill the current deposit to the current Deplink field.