TAILIEUCHUNG - Retrieving Hierarchical Data into a DataSet

[ Team LiB ] Recipe Retrieving Hierarchical Data into a DataSet Problem You want to fill a DataSet with parent and related child data, even if the DataSet already has a schema that includes the relationship. Solution There are several techniques you can use to load parent and child data into a DataSet. | Team LiB Recipe Retrieving Hierarchical Data into a DataSet Problem You want to fill a DataSet with parent and related child data even if the DataSet already has a schema that includes the relationship. Solution There are several techniques you can use to load parent and child data into a DataSet. The sample code contains three event handlers Sets up the sample by creating a DataSet with table schemas for both the Orders table and the Order Details table from Northwind and a DataRelation object relating these two tables. The default view of the parent table Orders is bound to a data grid on the form. Load DataSet Starts by clearing the data from the DataSet and refreshing the data grid. DataAdapter objects are created for both the parent and the child table. The Orders and Order Details are then filled using data adapters in the sequence specified and enforcing constraints during the load as specified by the user. The C code is shown in Example 2-1. Example 2-1. File Namespaces variables and constants using System using using using using private DataSet ds . . . private void HierarchicalDataSetForm_Load object sender e ds new DataSet Get the schema for the Orders table. DataTable parentTable new DataTable Orders SqlDataAdapter da new SqlDataAdapter SELECT FROM Orders S ql_ConnectString parentTable parentTable Get the schema for the Order Details table. DataTable childTable new DataTable Order Details da new SqlDataAdapter SELECT FROM Order Details S ql_ConnectString childTable childTable Add the relation between the tables. DataRelation dr new DataRelation Order_OrderDetails_Relation OrderID OrderID dr Bind

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã 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.