Đang chuẩn bị liên kết để tải về tài liệu:
Adding Records with a GUID Primary Key

Không đóng trình duyệt đến khi xuất hiện nút TẢI XUỐNG

[ Team LiB ] Recipe 4.6 Adding Records with a GUID Primary Key Problem You want to add records to a DataTable that uses a GUID as its primary key and has related child records. Solution Use the DataTable.RowChanging event handler. | Team LiB Recipe 4.6 Adding Records with a GUID Primary Key Problem You want to add records to a DataTable that uses a GUID as its primary key and has related child records. Solution Use the DataTable.RowChanging event handler. The sample code contains three event handlers Form.Load Sets up the sample by creating a DataSet containing two tables a parent and child both having a GUID primary key column with the DefaultValue set to a new GUID. A relation based on the parent table GUID and a foreign key GUID in the child table is added to the DataSet. The default view of the parent table is bound to the data grid on the form. Event handlers are added for the RowChanging event in both the parent and child DataTable objects. Parent DataTable.RowChanging Sets the default value of the primary key column in the parent table to a new GUID value when a new row has been added to the parent table. Child DataTable.RowChanging Sets the default value of the primary key column in the child table to a new GUID value when a new row has been added to the child table. The C code is shown in Example 4-9. Example 4-9. File AddGuidPKRecordForm.cs Namespaces variables and constants using System using System.Data using System.Data.SqlClient Table name constants private const String PARENTTABLENAME ParentTable private const String CHILDTABLENAME ChildTable Table column name constants for Parent table private const String PARENTID_FIELD ParentId private const String FIELD1_FIELD Fieldl private const String FIELD2_FIELD Field2 Table column parameter name constants for Parent table private const String CHILDID_FIELD ChildId private const String FIELD3_FIELD Field3 private const String FIELD4_FIELD Field4 private DataSet ds . . . private void AddGuidPKRecordForm_Load object sender System.EventArgs e DataColumnCollection cols DataColumn col Build the parent table. DataTable parentTable new DataTable PARENTTABLENAME cols parentTable.Columns col cols.Add PARENTID_FIELD typeof Guid col.DefaultValue

TÀI LIỆU LIÊN QUAN
Đã 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.