asp.net.ph

ConstraintCollection.Add Method

System.Data Namespace   ConstraintCollection Class


Adds a constraint to the collection.

Overload List

1. Adds the specified constraint to the collection.

2. Constructs a new UniqueConstraint, using the specified DataColumn, and adds it to the collection.

3. Constructs a new ForeignKeyConstraint, with the specified parent and child columns, and adds the constraint to the collection.

4. Constructs a new UniqueConstraint using the specified array of DataColumn objects, and adds it to the collection.

5. Constructs a new ForeignKeyConstraint, with the specified parent columns and child columns, and adds the constraint to the collection.


Example

NOTE: This example uses one of the overloaded versions of Add. For other examples that may be available, see the individual overload topics.

private void AddForeignConstraint ( DataSet myDataSet, DataTable myTable ) {
   try {
      DataColumn [ ] parentCols = new DataColumn [ 2 ];
      DataColumn [ ] childCols = new DataColumn [ 2 ];
      // get the tables from the DataSet.
      DataTable tCustomers = myDataSet.Tables [ "Customers" ];
      DataTable tOrders = myDataSet.Tables [ "Orders" ];

      // set Columns.
      parentCols [ 0 ] =tCustomers.Columns [ "id" ];
      parentCols [ 1 ] =tCustomers.Columns [ "Name" ];
      childCols [ 0 ] = tOrders.Columns [ "CustID" ];
      childCols [ 1 ] = tOrders.Columns [ "CustName" ];

      // create ForeignKeyConstraint
      myTable.Constraints.Add ( "CustOrdersConstraint", parentCols, childCols );
   }
   catch ( Exception myException ) {
      Response.Write ( myException.Message );
   }
}
  C# VB

See Also

ConstraintCollection Members Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph