DataRelationCollection.AddRange(DataRelation[]) メソッド

定義

指定した DataRelation 配列の要素をコレクションの末尾にコピーします。Copies the elements of the specified DataRelation array to the end of the collection.

public:
 virtual void AddRange(cli::array <System::Data::DataRelation ^> ^ relations);
public virtual void AddRange (System.Data.DataRelation[] relations);
abstract member AddRange : System.Data.DataRelation[] -> unit
override this.AddRange : System.Data.DataRelation[] -> unit
Public Overridable Sub AddRange (relations As DataRelation())

パラメーター

relations
DataRelation[]

コレクションに追加する DataRelation オブジェクトの配列。The array of DataRelation objects to add to the collection.

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());
}
Public Shared Sub AddRelations(dataSet As DataSet)
    Dim customerOrders As New DataRelation("CustomerOrders", _
        dataSet.Tables("Customers").Columns("customerId"), _
        dataSet.Tables("Orders").Columns("customerId"))
    Dim orderDetails As 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.
    Dim relation As DataRelation
    For Each relation In dataSet.Relations
        Console.WriteLine(relation.RelationName.ToString())
    Next
End Sub

注釈

BeginInit呼び出されているAddRange場合、は、が呼び出されるまでEndInit 、コレクションにオブジェクトを追加しません。If BeginInit has been called, AddRange does not add any objects to the collection until EndInit is called. EndInitが呼び出されたときに、コレクションには、の最後のAddRange呼び出しで指定された項目が設定されます。At the time that EndInit is called, the collection will be populated with the items specified in the most recent call to AddRange. AddRange シーケンスEndInit AddRange内でBeginInit 複数回呼び出された場合、の最後の呼び出しで指定された / 項目だけが追加されます。If AddRange is called multiple times within a BeginInit / EndInit sequence, only those items specified in the most recent call to AddRange are added.

適用対象

こちらもご覧ください