Adding Records with a GUID Primary Key

[ Team LiB ] Recipe 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 event handler. | Team LiB Recipe 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 event handler. The sample code contains three event handlers 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 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 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 Namespaces variables and constants using System using using 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 e DataColumnCollection cols DataColumn col Build the parent table. DataTable parentTable new DataTable PARENTTABLENAME cols col PARENTID_FIELD typeof Guid

Bấm vào đây để xem trước nội dung
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.