Navigating Between Parent and Child Tables in an Untyped DataSet : DataSet « ADO.Net « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » ADO.Net » DataSet 
32.35.14.Navigating Between Parent and Child Tables in an Untyped DataSet
using System;
using System.Data;
using System.Data.SqlClient;

    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;";

            DataSet ds = new DataSet( );
            SqlDataAdapter da;

            da = new SqlDataAdapter(sqlSelect, sqlConnectString);
            da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
            da.TableMappings.Add("Table""SalesOrderHeader");
            da.TableMappings.Add("Table1""SalesOrderDetail");
            da.Fill(ds);

            DataRelation dr = new DataRelation("SalesOrderHeader_SalesOrderDetail",
                ds.Tables["SalesOrderHeader"].Columns["SalesOrderID"],
                ds.Tables["SalesOrderDetail"].Columns["SalesOrderID"]);
            ds.Relations.Add(dr);

            for (int i = 0; i < 2; i++){
                DataRow rowHeader = ds.Tables["SalesOrderHeader"].Rows[i];
                Console.WriteLine("HEADER: OrderID = {0}, CustomerID = {1}",rowHeader["SalesOrderID"],rowHeader["CustomerID"]);
                foreach (DataRow rowDetail in rowHeader.GetChildRows(dr))
                {
                    Console.WriteLine(rowDetail["SalesOrderID"]);
                    Console.WriteLine(rowDetail["SalesOrderDetailID"]);
                    Console.WriteLine(rowDetail["LineTotal"]);
                    Console.WriteLine(rowDetail.GetParentRow(dr)["CustomerID"]);
                }
            }
        }
    }
32.35.DataSet
32.35.1.Simple Query Dataset
32.35.2.Fill a DataSet
32.35.3.Find Rows In Data
32.35.4.Load XML to DataSet
32.35.5.DataSet Merge event
32.35.6.Merge two DataSet
32.35.7.Creating a Strongly Typed DataSet
32.35.8.DataSet Read with SqlDataAdapter
32.35.9.DataSet.DataTable count
32.35.10.DataSet.DataTable name
32.35.11.Mapping Table and Column Names Between a Data Source and DataSet
32.35.12.Retrieving Schema and Constraints for a DataSet
32.35.13.Read schema and reload data with DataSet
32.35.14.Navigating Between Parent and Child Tables in an Untyped DataSet
32.35.15.Multitabled DataSet App
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.