Private void ConstraintsDemo ( DataSet myDataSet, string table1,
string table2, string column1, string column2 ) {
ForeignKeyConstraint idKey = new ForeignKeyConstraint
( myDataSet.Tables [ Table1 ].Columns [ Column1 ],
myDataSet.Tables [ Table2 ].Columns [ Column2 ] );
// set null values when a value is deleted.
idKey.DeleteRule = Rule.SetNull;
idKey.UpdateRule = Rule.Cascade;
// set AcceptRejectRule to cascade changes.
idKey.AcceptRejectRule = AcceptRejectRule.Cascade;
myDataSet.Tables [ Table1 ].Constraints.Add ( idKey );
myDataSet.EnforceConstraints = true;
}
Private Sub ConstraintsDemo ( myDataSet As DataSet, table1 As String, _
table2 As String, column1 As String, column2 As String )
Dim idKey As New ForeignKeyConstraint _
( myDataSet.Tables ( table1 ).Columns ( column1 ), _
myDataSet.Tables ( table2 ).Columns ( column2 ) )
' set null values when a value is deleted.
idKey.DeleteRule = Rule.SetNull
idKey.UpdateRule = Rule.Cascade
' set AcceptRejectRule to cascade changes.
idKey.AcceptRejectRule = AcceptRejectRule.Cascade
myDataSet.Tables ( table1 ).Constraints.Add ( idKey )
myDataSet.EnforceConstraints = True
End Sub |