DataRelationCollection.AddRange(DataRelation[]) 方法

定义

将指定的 DataRelation 数组的元素复制到集合末尾。

public:
 virtual void AddRange(cli::array <System::Data::DataRelation ^> ^ relations);
public virtual void AddRange (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 对象的数组。

示例

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 不会向集合添加任何对象。 在调用 时 EndInit ,集合将使用最近对 AddRange的调用中指定的项填充。 如果在AddRange序列EndInitBeginInit / 中多次调用 ,则仅添加在最近调用 AddRange 中指定的项。

适用于

另请参阅