Export (0) Print
Expand All

DataRelationCollection.AddRange Method

Copies the elements of the specified DataRelation array to the end of the collection.

Namespace:  System.Data
Assembly:  System.Data (in System.Data.dll)

public virtual void AddRange(
	DataRelation[] relations
)

Parameters

relations
Type: System.Data.DataRelation[]

The array of DataRelation objects to add to the collection.

If BeginInit has been called, AddRange does not add any objects to the collection until EndInit is called. At the time that EndInit is called, the collection will be populated with the items specified in the most recent call to AddRange. If AddRange is called multiple times within a BeginInit / EndInit sequence, only those items specified in the most recent call to AddRange are added.

public static void AddRelations(DataSet dataSet)
{
    DataRelation customerOrders = 
        new DataRelation("CustomerOrders",
        dataSet.Tables["Customers"].Columns["customerId"],
        dataSet.Tables["Orders"].Columns["customerId"]);

    DataRelation orderDetails = 
        new DataRelation("OrderDetail",
        dataSet.Tables["Orders"].Columns["orderId"],
        dataSet.Tables["OrderDetails"].Columns["orderId"]);

    dataSet.Relations.AddRange(new DataRelation[] 
        {customerOrders, orderDetails});

    // Display names of all relations. 
    foreach (DataRelation relation in dataSet.Relations)
        Console.WriteLine(relation.RelationName.ToString());
}

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft