DataSet.EnforceConstraints 속성

정의

업데이트 작업을 수행할 때 제약 조건 규칙을 따르는지 여부를 나타내는 값을 가져오거나 설정합니다.

public:
 property bool EnforceConstraints { bool get(); void set(bool value); };
public bool EnforceConstraints { get; set; }
[System.Data.DataSysDescription("DataSetEnforceConstraintsDescr")]
public bool EnforceConstraints { get; set; }
member this.EnforceConstraints : bool with get, set
[<System.Data.DataSysDescription("DataSetEnforceConstraintsDescr")>]
member this.EnforceConstraints : bool with get, set
Public Property EnforceConstraints As Boolean

속성 값

Boolean

true규칙이 적용되는 경우 그렇지 않으면 . false 기본값은 true입니다.

특성

예외

제약 조건을 적용할 수 없는 경우

예제

다음 예제에서는 테이블 1 DataSet 개, 열 1개, 행 5개, 행 1 UniqueConstraint개를 사용하여 만듭니다. 속성이 EnforceConstraints 설정 false 되고 각 행의 값이 동일한 값으로 설정됩니다. 속성이 EnforceConstraints 다시 설정 true되면 a ConstraintException 가 생성됩니다.

private void DemonstrateEnforceConstraints()
{
    // Create a DataSet with one table, one column and
    // a UniqueConstraint.
    DataSet dataSet= new DataSet("dataSet");
    DataTable table = new DataTable("table");
    DataColumn column = new DataColumn("col1");

    // A UniqueConstraint is added when the Unique
    // property is true.
    column.Unique=true;
    table.Columns.Add(column);
    dataSet.Tables.Add(table);
    Console.WriteLine("constraints.count: " +
        table.Constraints.Count);

    // add five rows.
    DataRow row ;
    for(int i=0;i<5;i++)
    {
        row = table.NewRow();
        row["col1"] = i;
        table.Rows.Add(row);
    }
    table.AcceptChanges();

    dataSet.EnforceConstraints=false;
    // Change the values of all rows to 1.
    foreach(DataRow thisRow in table.Rows)
    {
        thisRow["col1"]=1;
        //Console.WriteLine("\table" + thisRow[0]);
    }
    try
    {
        dataSet.EnforceConstraints=true;
    }
    catch(System.Data.ConstraintException e)
    {
        // Process exception and return.
        Console.WriteLine("Exception of type {0} occurred.",
            e.GetType());
    }
}
Private Sub DemonstrateEnforceConstraints()
    ' Create a DataSet with one table, one column and 
    ' a UniqueConstraint.
    Dim dataSet As New DataSet("dataSet")
    Dim table As New DataTable("table")
    Dim column As New DataColumn("col1")
    column.Unique = True
    table.Columns.Add(column)
    dataSet.Tables.Add(table)
    Console.WriteLine("constraints.count: " _
        & table.Constraints.Count)

    ' add five rows.
    Dim row As DataRow
    Dim i As Integer
    For i = 0 To 4
       row = table.NewRow()
       row("col1") = i
       table.Rows.Add(row)
    Next
    table.AcceptChanges()
     
    dataSet.EnforceConstraints = False
    ' Change the values of all rows to 1.
    Dim thisRow As DataRow
    For Each thisRow In table.rows
       thisRow("col1") = 1
    Next
 
    Try
        dataSet.EnforceConstraints = True
    Catch e As System.Data.ConstraintException
        ' Process exception and return.
        Console.WriteLine("Exception of type {0} occurred.", _
            e.GetType().ToString())
    End Try
End Sub

설명

제약 조건은 수준(Constraints속성)에서 DataTable 설정됩니다. 제약 조건을 만드는 방법에 대한 자세한 내용은 DataTable 제약 조건을 참조하세요.

적용 대상

추가 정보