Retrieve Child and Parent column values in ADO.NET


chsakell's Blog

In ADO.NET you can compute Child or Parent column values, coming from DataTable objects that are related using a DataRelation between them. If you don’t know how DataRelation is used in ADO.NET read a previous post of these ADO.NET series. This post will describe you the following procedures:

  1. Adding a column to a child DataTable that displays a Parent’s column value
  2. Adding a column to a parent DataTable that Aggregates a Child Table’s Column Values

Adding a column to a child DataTable that displays a Parent’s column value

Let’start. Open Visual Studio and create a new console application project named RetrieveChildAndParentValuesAdoNet. Add using statements for System.Data and System.Data.SqlClient namespaces. We are going to use AdventureWorks database in this example and more specifically, two related Tables, Product and ProductSubcategory from Production. Each Product record has a foreign key pointing to a ProductSubcategory record, through the ProductSubcategoryID primary key. What we…

View original post 397 more words