RAD Studio for Microsoft .NET
ContentsIndex
PreviousUpNext
Using DB Web Controls in Master-Detail Applications

Note: DB Web Controls (Borland.Data.Web namespace) are being deprecated in 2007. You should use standard Web controls instead.
DB Web Controls allow you to build full-fledged master-detail applications, using the DBWebDataSource, DBWebGrid, and DBWebNavigator controls. To support master-detail applications, these controls must provide a way to specify cascading behavior. 

This topic includes information about:

  • Specifying Cascading Deletes
  • Specifying Cascading Updates

In a master-detail application, the application typically uses an OnApplyChanges event to send the DataSet changes to the server. It is necessary for the master data adapter's update method (in BDP.NET, the AutoUpdate event) to be called prior to the detail data adapter's update method. Otherwise, insertion of detail rows fails if the master row has not yet been inserted. If the master row is deleted prior to the detail row, the server might return an error. 

The property CascadingDeletes has been added to the DBWebDataSource control. The CascadingDeletes property specifies how the server deletes rows in master-detail applications. The CascadingDeletes property provides the following three options:

  • NoMasterDelete (Default)
  • ServerCascadeDelete
  • ServerNoForeignKey
Note: When DB Web Controls are connected to a DataTable that is a detail table in a relation, the control's rows are automatically limited to the rows controlled by the current parent row in the master table.

NoMasterDelete

This option does not allow deletion of a master row containing detail rows. This option should be used when the server enforces a foreign constraint between master and detail, but it does handle cascading deletes. You must:

  1. Delete detail rows.
  2. Apply the changes with an apply event (for example, the BdpDataAdapter. AutoUpdate event).
  3. Delete the master row.
  4. Call the apply event (for example, the BdpDataAdapter. AutoUpdate event).
This option is the default value for the CascadingDeletes property.

ServerCascadeDelete

This option allows deletion of the master row. This option should be specified whenever the server is set up to automatically handle cascading deletes. When a master row is deleted, the detail rows will automatically disappear from view. Any time prior to applying the change, you can undo the parent row deletion and all the detail rows come back into view. If the server is not set up to handle cascading deletes, an error may occur when attempting to send changes to the server.

ServerNoForeignKey

This option automatically deletes all detail rows whenever a master row is deleted. This option should be specified whenever there are no foreign key constraints between the master-detail tables on the server. Like the ServerCascadeDelete option, when a master row is deleted, the detail rows will automatically disappear from view. Any time prior to applying the change, it is possible to undo the master row deletion to redisplay the detail rows. If you specify this option and foreign key constraints exist between master and detail tables, an error will be thrown by the server when attempting to delete the master table.

In a master-detail application, the application typically uses an OnApplyChanges event to send the DataSet changes to the server. It is necessary for the update method of the master data adapter (in BDP.NET, the AutoUpdate event) to be called prior to the update method of the detail data adapter. Otherwise, insertion of detail rows fails if the master row has not yet been inserted. If the master row is deleted prior to the detail row, the server might return an error. 

The property CascadingUpdates has been added to the DBWebDataSource control. This property specifies how the server updates foreign-key values in master-detail applications. The CascadingUpdates property provides the following three options:

  • NoMasterUpdate (default)
  • ServerCascadeUpdate
  • ServerNoForeignKey
Note: When DB Web Controls are connected to a DataTable that is a detail table in a relation, the rows of the control are automatically limited to the rows controlled by the current parent row in the master table.

NoMasterUpdate

This option does not allow changes to the foreign key value of a master row if it has any associated detail rows. This option is the default value for the CascadingUpdates property.

ServerCascadeUpdate

This option allows you to change the foreign key value of the master row. You should use this option whenever the server automatically handles cascading updates. When the foreign key value of a master row is changed, the key value is changed automatically in the detail rows. Anytime prior to applying the change, you can undo the change to the master row and all the detail key changes will be undone also. If the server is not set up to handle cascading updates, an error might occur when attempting to update the changes to the server.

ServerNoForeignKey

This option also allows changing the foreign key value of the parent row, but should be used whenever there is no foreign key between the master and detail tables on the server.

Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
What do you think about this topic? Send feedback!