ConstraintCollection.AddRange(Constraint[]) Metoda

Definice

Zkopíruje prvky zadaného ConstraintCollection pole na konec kolekce.

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())

Parametry

constraints
Constraint[]

Pole ConstraintCollection objektů, které se mají přidat do kolekce.

Příklady

Následující příklad vytvoří omezení primárního a cizího ConstraintCollectionklíče a přidá je do .

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

Poznámky

Pokud BeginInit byl volána, AddRange nepřidá do kolekce žádné objekty, dokud EndInit není volána. V době EndInit volání se kolekce naplní položkami zadanými v posledním volání .AddRange Pokud AddRange je volána vícekrát v rámci posloupnostiEndInitBeginInit / , jsou přidány pouze položky zadané v posledním volání.AddRange

Platí pro