Aracılığıyla paylaş


ConstraintCollection.AddRange(Constraint[]) Yöntem

Tanım

Belirtilen ConstraintCollection dizinin öğelerini koleksiyonun sonuna kopyalar.

public:
 void AddRange(cli::array <System::Data::Constraint ^> ^ constraints);
public void AddRange (System.Data.Constraint[]? constraints);
public void AddRange (System.Data.Constraint[] constraints);
member this.AddRange : System.Data.Constraint[] -> unit
Public Sub AddRange (constraints As Constraint())

Parametreler

constraints
Constraint[]

Koleksiyona eklenecek nesne dizisi ConstraintCollection .

Örnekler

Aşağıdaki örnek birincil ve yabancı anahtar kısıtlamaları oluşturur ve bunları öğesine ConstraintCollectionekler.

public static void ConstraintAddRange(DataSet dataSet)
{
    try
    {
        // Reference the tables from the DataSet.
        DataTable customersTable = dataSet.Tables["Customers"];
        DataTable ordersTable = dataSet.Tables["Orders"];

        // Create unique and foreign key constraints.
        UniqueConstraint uniqueConstraint = new
            UniqueConstraint(customersTable.Columns["CustomerID"]);
        ForeignKeyConstraint fkConstraint = new
            ForeignKeyConstraint("CustOrdersConstraint",
            customersTable.Columns["CustomerID"],
            ordersTable.Columns["CustomerID"]);

        // Add the constraints.
        customersTable.Constraints.AddRange(new Constraint[]
            {uniqueConstraint, fkConstraint});
    }
    catch(Exception ex)
    {
        // Process exception and return.
        Console.WriteLine("Exception of type {0} occurred.",
            ex.GetType());
    }
}
Public Shared Sub ConstraintAddRange(dataSet As DataSet)
    Try
        ' Reference the tables from the DataSet.
        Dim customersTable As DataTable = dataSet.Tables("Customers")
        Dim ordersTable As DataTable = dataSet.Tables("Orders")

        ' Create unique and foreign key constraints.
        Dim uniqueConstraint As New UniqueConstraint( _
            customersTable.Columns("CustomerID"))
        Dim fkConstraint As New ForeignKeyConstraint("CustOrdersConstraint", _
            customersTable.Columns("CustomerID"), _
            ordersTable.Columns("CustomerID"))

        ' Add the constraints.
        customersTable.Constraints.AddRange(New Constraint() _
            {uniqueConstraint, fkConstraint})

    Catch ex As Exception
        ' Process exception and return.
        Console.WriteLine($"Exception of type {ex.GetType()} occurred.")
    End Try
End Sub

Açıklamalar

çağrıldıysa BeginInit , AddRange çağrılana kadar EndInit koleksiyona hiçbir nesne eklemez. Çağrılan zamanda EndInit , koleksiyon en son çağrısında AddRangebelirtilen öğelerle doldurulur. BirEndInitBeginInit / dizi içinde birden çok kez çağrılırsaAddRange, yalnızca en son çağrısında AddRange belirtilen öğeler eklenir.

Şunlara uygulanır