| ||||||||||||||||||||||||||||||||||||||
Constraint ClassRepresents a constraint that can be enforced on one or more DataColumn objects.
|
||||||||||||||||||||||||||||||||||||||
| Visibility | Name | Parameters | Return Type |
|---|---|---|---|
| protected | CheckStateForProperty | ( ) | Void |
| public | ToString | ( ) | String |
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.
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 | |
ConstraintCollection Constraints ForeignKeyConstraint UniqueConstraint
Check out related books at Amazon
© 2000-2008 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 aspxtreme