Creating Constraints, PrimaryKeys, Relationships Based on Multiple Columns

[ Team LiB ] Recipe Creating Constraints, PrimaryKeys, Relationships Based on Multiple Columns Problem You need to create a constraint, primary key, or a relationship between two tables in a DataSet using more than one column. Solution Use the . | Team LiB Recipe Creating Constraints PrimaryKeys Relationships Based on Multiple Columns Problem You need to create a constraint primary key or a relationship between two tables in a DataSet using more than one column. Solution Use the and types. The sample code creates a DataSet containing two tables Parent and Child. A multicolumn unique constraint and primary key are created for the Parent table. A multicolumn foreign-key constraint is created on the Child table. Finally a DataRelation between the primary key in the Parent table and the foreign key in the Child table is created. The C code is shown in Example 6-26. Example 6-26. File Namespaces variables and constants using System using using . . . StringBuilder result new StringBuilder DataSet ds new DataSet Create the parent table. Creating parent table. DataTable dtParent new DataTable Parent DataColumnCollection pCols ParentKey1 typeof Int32 ParentKey2 typeof lnt32 ParentData1 typeof String ParentData2 typeof String Set the multicolumn unique constraint. Creating unique constraint on parent table. new UniqueConstraint UConstraint new DataColumn pCols ParentKey1 pCols ParentKey2 false Set the multicolumn primary key. Creating primary key on parent table. new DataColumn pCols ParentKey1 pCols ParentKey2 Add the parent table to the DataSet. . Add dtParent Create the child table. Creating child table. DataTable dtChild new DataTable Child DataColumnCollection cCols ChildIndex1 typeof Int32 .Unique true ParentKey1 typeof Int32 ParentKey2 typeof lnt32 ChildData1 typeof String .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.