3.8. Working with Parent-Child Relations in a Strongly Typed DataSet
Problem
You have retrieved data into related tables in a strongly typed DataSet and you need to navigate the hierarchy and retrieve data values.
Solution
The solution shows how to work with related data tables in a strongly typed DataSet.
Follow these steps:
Create a new C# Windows Console application, and name it
AccessValuesStronglyTypedDataSet.The solution needs the strongly typed
DataSetclass file AdventureWorks.cs created in the second half of Recipe 2.16. Copy this file to the project folder—the folder that contains the file AccessValuesStronglyTypedDataSet.csproj.Add the strongly typed
DataSetclass to the project. Right-click on the project in Solution Explorer. Select Add → Existing Item to open the Add Existing Item dialog. Select the AdventureWorks.cs file and click Add. You can now use the strongly typedDataSet AdventureWorksin your project.The C# code in Program.cs in the project
DataRelationStronglyTypedDataSetis shown in Example 3-11.
Example 3-11. File: Program.cs for DataRelationStronglyTypedDataSet solution
using System;
using System.Data;
using System.Data.SqlClient;
namespace Data RelationStronglyTypedDataSet { class Program { static void Main(string[] args) { string sqlConnectString = "Data Source=(local);" + "Integrated security=SSPI;Initial Catalog=AdventureWorks;"; string sqlSelect = "SELECT * FROM Sales.SalesOrderHeader;" + "SELECT * FROM Sales.SalesOrderDetail;"; AdventureWorks awds = new ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access