asp.net.ph

Constraint Class

System.Data Namespace


Represents a constraint that can be enforced on one or more DataColumn objects.

Constraint Class Members

Collapse   Properties

Visibility Name Value Type Accessibility
public ConstraintName String [ Get , Set ]
public ExtendedProperties PropertyCollection [ Get ]
public Table DataTable [ Get ]

Collapse   Methods

Visibility Name Parameters Return Type
protected CheckStateForProperty ( ) Void
public ToString ( ) String

Remarks

A constraint is a rule used to maintain the integrity of data in a DataTable. ADO.NET includes two constraints: a UniqueConstraint and a ForeignKeyConstraint.

A UniqueConstraint simply ensures that values in a table are unique, whereas a ForeignKeyConstraint determines what action to take when a value in a column that is used in one or more related tables is modified. For more information, see Adding Constraints to a Table.

A base Constraint constructor is not used. Primary or unique key constraints are created using the UniqueConstraint constructor, and foreign key constraints are created using the ForeignKeyConstraint constructor.

Example

The following example checks the collection of constraints in a DataTable and determines if the constraint is a UniqueConstraint or a ForeignKeyConstraint.

private void GetConstraints ( DataTable myTable ) {
   // print the table' s name.
   Response.Write ( "TableName: " + myTable.TableName );

   // iterate through the collection and print each name and type value.
   foreach ( Constraint cs in myTable.Constraints ) {
      Response.Write ( "Constraint Name: " + cs.ConstraintName );
      Response.Write ( "Type: " + cs.GetType ( ).ToString ( ) );
   }
}
  C# VB

See Also

ConstraintCollection   Constraints   ForeignKeyConstraint   UniqueConstraint 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