ODAC Application Skills (iii) master/schedule

Source: Internet
Author: User
Tags numeric

The master/detail relationship between two tables is widely used. It is therefore important to provide a simple way for database application developers to implement it. Let's take a look at how to implement this feature.

If we establish a master/BOM relationship between "Department" and "Employee". The Department table contains the following fields: Depno, Depname, and Location. Depno is a numeric 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 numeric fields, and EmpName and Job are string fields. EmpNo is a primary key and Depno is a foreign key that binds "Employee" and "Department".

This is required to display and edit data tables.

ODAC provides two methods of binding data tables. The first code example shows the binding of two Toradataset components (Toraquery, Tsmartquery, toratable, or Torastoredproc) to a master/detail relationship through a parameter.

procedure TForm1.Form1Create(Sender: TObject);
var
Master, Detail: TOraQuery;
MasterSource: TDataSource;
begin
// 创建主数据集
Master := TOraQuery.Create(Self);
Master.SQL.Text := 'SELECT * FROM Department';

To create a detail dataset

Detail := TOraQuery.Create(Self);
Detail.SQL.Text := 'SELECT * FROM Employee WHERE DepNo = :DepNo';

// 主表通过 TDataSource 组件来连接明细表
MasterSource := TDataSource.Create(Self);
MasterSource.DataSet := Master;
Detail.MasterSource := MasterSource;

Open the main dataset and the detail dataset

Master.Open;
Detail.Open;
end;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.