This documentation is archived and is not being maintained.

Suspending Update Constraints

If a dataset contains constraints (such as a foreign-key constraint), updating a column in a record can violate the constraint: After you have finished updating one column but before you get to the next one, the record can temporarily be in an error state. For example, imagine that you have a data table in your dataset with two columns that do not allow null values. As soon as you start to write a new record there will always be a null value in at least one of the columns (you can only write one column at a time). If there were no mechanism to allow temporary constraint suspension, an error would be raised every time after writing the first column and before writing the second.

To suspend update constraints

  1. Before changing data in a data row, call the DataRow object's BeginEdit method.
    Note   Changes you make to the row after calling BeginEdit are saved.
  2. Make the updates to that row.
  3. Call the EndEdit method to commit changes to the row and re-enable constraint checking.

    The RowChanging event is raised.

  4. Call the row's CancelEdit method to discard changes to the row.

    The following example shows a simple update that is bracketed with BeginEdit and EndEdit method calls. This example assumes that you have a table called Customers in a typed dataset called DsCustomers1.

    ' Visual Basic
    DsCustomers1.Customers(4).BeginEdit()
    DsCustomers1.Customers(4).CompanyName = "Wingtip Toys"
    DsCustomers1.Customers(4).City = "Buffalo"
    DsCustomers1.Customers(4).EndEdit()
    
    // C#
    dsCustomers1.Customers[4].BeginEdit();
    dsCustomers1.Customers[4].CompanyName = "Wingtip Toys";
    dsCustomers1.Customers[4].City = "Buffalo";
    dsCustomers1.Customers[4].EndEdit();
    

See Also

Introduction to Dataset Updates | Updating, Inserting, and Deleting Records in a Dataset | Data Update Events | BeginEdit | EndEdit | CancelEdit | RowChanging Event | Code: Turning Off Constraints While Filling a DataSet (Visual Basic)

Show: