Constraint Constraint Constraint Constraint Class

定義

1 つ以上の DataColumn オブジェクトに適用できる制約を表します。Represents a constraint that can be enforced on one or more DataColumn objects.

public ref class Constraint abstract
[System.ComponentModel.TypeConverter(typeof(System.Data.ConstraintConverter))]
[System.Serializable]
public abstract class Constraint
type Constraint = class
Public MustInherit Class Constraint
継承
ConstraintConstraintConstraintConstraint
派生
属性

次の例の制約のコレクションを調べて、DataTableし、各制約がどうかを決定、UniqueConstraintまたはForeignKeyConstraintします。The following example examines the collection of constraints for a DataTable and determines whether each constraint is a UniqueConstraint or a ForeignKeyConstraint. 制約のプロパティは表示されます。The properties of the constraint are then displayed.

private void GetConstraints(DataTable dataTable)
{
    Console.WriteLine();

    // Print the table's name.
    Console.WriteLine("TableName: " + dataTable.TableName);

    // Iterate through the collection and 
    // print each name and type value.
    foreach(Constraint constraint in dataTable.Constraints ) 
    {
        Console.WriteLine("Constraint Name: " 
            + constraint.ConstraintName);
        Console.WriteLine("Type: " 
            + constraint.GetType().ToString());

        // If the constraint is a UniqueConstraint, 
        // print its properties using a function below.
        if(constraint is UniqueConstraint) 
        {
            PrintUniqueConstraintProperties(constraint);
        }
        // If the constraint is a ForeignKeyConstraint, 
        // print its properties using a function below.
        if(constraint is ForeignKeyConstraint) 
        {
            PrintForeigKeyConstraintProperties(constraint);
        }
    }
}

private void PrintUniqueConstraintProperties(
    Constraint constraint)
{
    UniqueConstraint uniqueConstraint;
    uniqueConstraint = (UniqueConstraint) constraint;

    // Get the Columns as an array.
    DataColumn[] columnArray;
    columnArray = uniqueConstraint.Columns;

    // Print each column's name.
    for(int i = 0;i<columnArray.Length ;i++) 
    {
        Console.WriteLine("Column Name: " 
            + columnArray[i].ColumnName);
    }
}

private void PrintForeigKeyConstraintProperties(
    Constraint constraint)
{
    ForeignKeyConstraint fkConstraint;
    fkConstraint = (ForeignKeyConstraint) constraint;

    // Get the Columns as an array.
    DataColumn[] columnArray;
    columnArray = fkConstraint.Columns;

    // Print each column's name.
    for(int i = 0;i<columnArray.Length ;i++) 
    {
        Console.WriteLine("Column Name: " 
            + columnArray[i].ColumnName);
    }
    Console.WriteLine();

    // Get the related columns and print each columns name.
    columnArray = fkConstraint.RelatedColumns ;
    for(int i = 0;i<columnArray.Length ;i++) 
    {
        Console.WriteLine("Related Column Name: " 
            + columnArray[i].ColumnName);
    }
    Console.WriteLine();
}
Private Sub GetConstraints(dataTable As DataTable)
    Console.WriteLine()

    ' Print the table's name.
    Console.WriteLine("TableName: " & dataTable.TableName)

    ' Iterate through the collection and print 
    ' each name and type value.
    Dim constraint As Constraint
    For Each constraint In  dataTable.Constraints
        Console.WriteLine("Constraint Name: " _
            & constraint.ConstraintName)
        Console.WriteLine("Type: " _
            & constraint.GetType().ToString())

        ' If the constraint is a UniqueConstraint, 
        ' print its properties using a function below.
        If TypeOf constraint Is UniqueConstraint Then
            PrintUniqueConstraintProperties(constraint)
        End If

        ' If the constraint is a ForeignKeyConstraint, 
        ' print its properties using a function below.
        If TypeOf constraint Is ForeignKeyConstraint Then
            PrintForeigKeyConstraintProperties(constraint)
        End If
    Next constraint
End Sub

Private Sub PrintUniqueConstraintProperties( _
    constraint As Constraint)

    Dim uniqueConstraint As UniqueConstraint
    uniqueConstraint = CType(constraint, UniqueConstraint)

    ' Get the Columns as an array.
    Dim columnArray() As DataColumn
    columnArray = uniqueConstraint.Columns

    ' Print each column's name.
    Dim i As Integer
    For i = 0 To columnArray.Length - 1
        Console.WriteLine("Column Name: " _
            & columnArray(i).ColumnName)
    Next i
End Sub

Private Sub PrintForeigKeyConstraintProperties( _
    constraint As Constraint)

    Dim fkConstraint As ForeignKeyConstraint
    fkConstraint = CType(constraint, ForeignKeyConstraint)
    
    ' Get the Columns as an array.
    Dim columnArray() As DataColumn
    columnArray = fkConstraint.Columns
    
    ' Print each column's name.
    Dim i As Integer
    For i = 0 To columnArray.Length - 1
        Console.WriteLine("Column Name: " _
            & columnArray(i).ColumnName)
    Next i
    Console.WriteLine()
    
    ' Get the related columns and print each columns name.
    columnArray = fkConstraint.RelatedColumns
    For i = 0 To columnArray.Length - 1
        Console.WriteLine("Related Column Name: " _
            & columnArray(i).ColumnName)
    Next i
    Console.WriteLine()
End Sub

注釈

制約内のデータの整合性を維持するために使用される規則とは、DataTableします。A constraint is a rule used to maintain the integrity of the data in the DataTable. ときにいずれかで使用される値を削除するなど、複数の関連するテーブルをForeignKeyConstraint関連テーブル内の値も削除するかどうかを決定、null 値に設定、設定を既定値、またはかどうかも何も起こりません。For example, when you delete a value that is used in one or more related tables, a ForeignKeyConstraint determines whether the values in the related tables are also deleted, set to null values, set to default values, or whether no action occurs. A UniqueConstraint、その一方で、特定のテーブル内のすべての値が一意であることを確認してだけなります。A UniqueConstraint, on the other hand, just makes sure that all values within a particular table are unique. 詳細については、次を参照してください。 DataTable の制約します。For more information, see DataTable Constraints.

基本Constraintコンス トラクターは使用されません。A base Constraint constructor is not used. プライマリまたは一意キー制約を使用して作成された、UniqueConstraintコンス トラクター、および外部キー制約を使用して作成された、ForeignKeyConstraintコンス トラクター。Primary or unique key constraints are created by using the UniqueConstraint constructor, and foreign key constraints are created by using the ForeignKeyConstraint constructor.

コンストラクター

Constraint() Constraint() Constraint() Constraint()

Constraint クラスの新しいインスタンスを初期化します。Initializes a new instance of the Constraint class.

プロパティ

ConstraintName ConstraintName ConstraintName ConstraintName

ConstraintCollection 内の制約の名前。The name of a constraint in the ConstraintCollection.

ExtendedProperties ExtendedProperties ExtendedProperties ExtendedProperties

ユーザー定義の制約のプロパティのコレクションを取得します。Gets the collection of user-defined constraint properties.

Table Table Table Table

制約を適用する DataTable を取得します。Gets the DataTable to which the constraint applies.

_DataSet _DataSet _DataSet _DataSet

この制約が属する DataSet を取得します。Gets the DataSet to which this constraint belongs.

メソッド

CheckStateForProperty() CheckStateForProperty() CheckStateForProperty() CheckStateForProperty()

この制約が属する DataSet を取得します。Gets the DataSet to which this constraint belongs.

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

指定したオブジェクトが、現在のオブジェクトと等しいかどうかを判断します。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

既定のハッシュ関数として機能します。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

現在のインスタンスの Type を取得します。Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

現在の Object の簡易コピーを作成します。Creates a shallow copy of the current Object.

(Inherited from Object)
SetDataSet(DataSet) SetDataSet(DataSet) SetDataSet(DataSet) SetDataSet(DataSet)

制約の DataSet を設定します。Sets the constraint's DataSet.

ToString() ToString() ToString() ToString()

ConstraintName がある場合は、この制約名を文字列として取得します。Gets the ConstraintName, if there is one, as a string.

適用対象

スレッド セーフ

この型は、マルチ スレッドの読み取り操作も安全です。This type is safe for multithreaded read operations. 書き込み操作を同期する必要があります。You must synchronize any write operations.

こちらもご覧ください