Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

ConstraintCollection.AddRange Method

Copies the elements of the specified ConstraintCollection array to the end of the collection.

Namespace: System.Data
Assembly: System.Data (in system.data.dll)

public void AddRange (
	Constraint[] constraints
)
public void AddRange (
	Constraint[] constraints
)
public function AddRange (
	constraints : Constraint[]
)

Parameters

constraints

An array of ConstraintCollection objects to add to the collection.

If BeginInit has been called, AddRange does not add any objects to the collection until EndInit is called. At the time that EndInit is called, the collection will be populated with the items specified in the most recent call to AddRange. If AddRange is called multiple times within a BeginInit / EndInit sequence, only those items specified in the most recent call to AddRange are added.

The following example creates primary and foreign key constraints, and adds them to the 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());
    


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.