ConstraintCollection.AddRange(Constraint[]) Metoda
Definice
Důležité
Některé informace platí pro předběžně vydaný produkt, který se může zásadně změnit, než ho výrobce nebo autor vydá. Microsoft neposkytuje žádné záruky, výslovné ani předpokládané, týkající se zde uváděných informací.
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é chcete přidat do kolekce.
Příklady
Následující příklad vytvoří omezení primárního a cizího klíče a přidá je do ConstraintCollection.
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á žádné objekty do kolekce, dokud EndInit nebude 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 posloupnostiBeginInit / EndInit, budou přidány pouze ty položky zadané v posledním volání.AddRange