TAILIEUCHUNG - Creating and Using a DataRelation Object

Creating and Using a DataRelation Object In this section, you'll learn how to create a DataRelation object to define a relationship between two DataTable objects that hold some rows from the Customers and Orders tables | Creating and Using a DataRelation Object In this section you ll learn how to create a DataRelation object to define a relationship between two DataTable objects that hold some rows from the Customers and Orders tables. As you know the CustomerlD column of the child Orders table is a foreign key that links to the CustomerlD column of the parent Customers table. Once you ve created a DataRelation you can use the GetChildRows method of a DataRow object in the parent DataTable to obtain the corresponding DataRow objects from the child DataTable. By corresponding I mean the rows that have matching values in the foreign key DataColumn objects. You can also use the GetParentRow method of a DataRow in the child DataTable to obtain the corresponding DataRow in the parent DataTable. Before creating and adding a DataRelation to a DataSet you first need a DataSet. The following example creates and populates a DataSet with two DataTable objects named customersDT and ordersDT notice that the top two rows from the Customers table along with the corresponding rows from the Orders table are retrieved SqlCommand mySqlCommand SELECT TOP 2 CustomerlD CompanyName FROM Customers ORDER BY CustomerlD SELECT OrderlD CustomerlD FROM Orders WHERE CustomerlD IN SELECT TOP 2 CustomerlD FROM Customers ORDER BY CustomerlD SqlDataAdapter mySqlDataAdapter new SqlDataAdapter mySqlCommand DataSet myDataSet new DataSet myDataSet Table .TableName Customers Table1 .TableName Orders DataTable customersDT Customers DataTable ordersDT Orders You ll see how to create a DataRelation that defines a relationship between the customersDT and ordersDT DataTable objects next. Note You ll find all the code examples shown in this section in the program. Creating the DataRelation

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.