Bạn hiểu gì về lớp DataRelation?
Bạn hiểu gì về lớp DataRelation?
DataRelation biểu diễn quan hệ cha–con (khoá chính–khoá ngoại) giữa hai DataTable trong DataSet, cho phép điều hướng và ràng buộc như CSDL quan hệ.
var rel = ds.Relations.Add("Cust_Orders", ds.Tables["Customers"]!.Columns["Id"]!, ds.Tables["Orders"]!.Columns["CustomerId"]!);
foreach (DataRow customer in ds.Tables["Customers"]!.Rows)
{
Console.WriteLine(customer["Name"]);
foreach (DataRow order in customer.GetChildRows(rel)) // dòng con
Console.WriteLine($" Đơn {order["Id"]}: {order["Total"]}");
}
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.