Determines the action that occurs when the AcceptChanges or RejectChanges method is invoked on a DataTable with a ForeignKeyConstraint.
[Visual Basic] <Serializable> Public Enum AcceptRejectRule [C#] [Serializable] public enum AcceptRejectRule [C++] [Serializable] __value public enum AcceptRejectRule [JScript] public Serializable enum AcceptRejectRule
Changes to a DataTable are not final until you call the AcceptChanges method. When either AcceptChanges or RejectChanges is called on a row in the parent table, the AcceptRejectRule value determines whether or not changes are propagated to corresponding rows in the child table.
| Member name | Description |
|---|---|
| Cascade
Supported by the .NET Compact Framework. |
Changes are cascaded across the relationship. |
| None
Supported by the .NET Compact Framework. |
No action occurs (default). |
[Visual Basic, C#] The following example creates a ForeignKeyConstraint, sets various of its properties, including the AcceptRejectRule, and adds it to a DataTable object's ConstraintCollection.
[Visual Basic] Private Sub CreateConstraint(myDataSet As DataSet, table1 As String, table2 As String, _ column1 As String, column2 As String) ' Declare parent column and child column variables. Dim parentColumn As DataColumn Dim childColumn As DataColumn Dim myForeignKeyConstraint As ForeignKeyConstraint ' Set parent and child column variables. parentColumn = MyDataSet.Tables(table1).Columns(column1) childColumn = MyDataSet.Tables(table2).Columns(column2) myForeignKeyConstraint = New ForeignKeyConstraint _ ("SupplierForeignKeyConstraint", parentColumn, childColumn) ' Set null values when a value is deleted. myForeignKeyConstraint.DeleteRule = Rule.SetNull myForeignKeyConstraint.UpdateRule = Rule.Cascade myForeignKeyConstraint.AcceptRejectRule = AcceptRejectRule.Cascade ' Add the constraint, and set EnforceConstraints to true. myDataSet.Tables(table1).Constraints.Add(myForeignKeyConstraint) myDataSet.EnforceConstraints = True End Sub [C#] private void CreateConstraint(DataSet myDataSet, string table1, string table2, string column1, string column2){ // Declare parent column and child column variables. DataColumn parentColumn; DataColumn childColumn; ForeignKeyConstraint myForeignKeyConstraint; // Set parent and child column variables. parentColumn = myDataSet.Tables[table1].Columns[column1]; childColumn = myDataSet.Tables[table2].Columns[column2]; myForeignKeyConstraint = new ForeignKeyConstraint ("SupplierForeignKeyConstraint", parentColumn, childColumn); // Set null values when a value is deleted. myForeignKeyConstraint.DeleteRule = Rule.SetNull; myForeignKeyConstraint.UpdateRule = Rule.Cascade; myForeignKeyConstraint.AcceptRejectRule = AcceptRejectRule.Cascade; // Add the constraint, and set EnforceConstraints to true. myDataSet.Tables[table1].Constraints.Add(myForeignKeyConstraint); myDataSet.EnforceConstraints = true; }
[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button
in the upper-left corner of the page.
Namespace: System.Data
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework - Windows CE .NET
Assembly: System.Data (in System.Data.dll)
System.Data Namespace | DataTable | UniqueConstraint | ForeignKeyConstraint | AcceptRejectRule