Export (0) Print
Expand All

DataRelationCollection.AddRange Method

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

[Visual Basic]
Public Overridable Sub AddRange( _
   ByVal relations() As DataRelation _
)
[C#]
public virtual void AddRange(
 DataRelation[] relations
);
[C++]
public: virtual void AddRange(
 DataRelation* relations[]
);
[JScript]
public function AddRange(
   relations : DataRelation[]
);

Parameters

relations
The array of DataRelation objects to add to the collection.

Remarks

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.

Example

[Visual Basic] 
Public Shared Sub AddRelations(myDataSet As DataSet)

    Dim r1 As DataRelation = New DataRelation("CustomerOrders", _
                                       myDataSet.Tables("Customers").Columns("customerId"), _
                                       myDataSet.Tables("Orders").Columns("customerId"))

    Dim r2 As DataRelation = New DataRelation("OrderDetail", _
                                       myDataSet.Tables("Orders").Columns("orderId"), _
                                       myDataSet.Tables("OrderDetails").Columns("orderId"))

    myDataSet.Relations.AddRange( New DataRelation() {r1, r2})

    ' Display names of all relations.
    Dim r As DataRelation
    For Each r In myDataSet.Relations
      Console.WriteLine(r.RelationName)
    Next
End Sub


[C#] 
public static void AddRelations(DataSet myDataSet)
{
    DataRelation r1 = new DataRelation("CustomerOrders",
                                       myDataSet.Tables["Customers"].Columns["customerId"],
                                       myDataSet.Tables["Orders"].Columns["customerId"]);

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

    myDataSet.Relations.AddRange( new DataRelation[] {r1, r2});

    // Display names of all relations.
    foreach (DataRelation r in myDataSet.Relations)
      Console.WriteLine(r.RelationName);
}


[C++] 

public:
static void AddRelations(DataSet* myDataSet) {

    DataRelation* r1 = new DataRelation(S"CustomerOrders",
        myDataSet->Tables->Item[S"Customers"]->Columns->Item[S"customerId"],
        myDataSet->Tables->Item[S"Orders"]->Columns->Item[S"customerId"]);

    DataRelation* r2 = new DataRelation(S"OrderDetail",
        myDataSet->Tables->Item[S"Orders"]->Columns->Item[S"orderId"],
        myDataSet->Tables->Item[S"OrderDetails"]->Columns->Item[S"orderId"]);

    DataRelation* relationsArray[] = {r1, r2};
    myDataSet->Relations->AddRange(relationsArray);

    // Display names of all relations:
    System::Collections::IEnumerator* myEnum = myDataSet->Relations->GetEnumerator();
    while (myEnum->MoveNext()) {
        DataRelation* r = __try_cast<DataRelation*>(myEnum->Current);
        Console::WriteLine(r->RelationName);
    }
};

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

DataRelationCollection Class | DataRelationCollection Members | System.Data Namespace

Show:
© 2014 Microsoft