Saving Parent-child Data in a Multitiered App Using ADO.NET

      In this month's column I will focus on some data management techniques commonly required in enterprise applications. These include saving parent-child data in a multitier application using ADO.NET, ADO.NET transactions, merge techniques, and a number of other ADO.NET features. I'll also discuss the best process for incorporating consistent and informative exception-handling techniques and debugging strategies into your multitier app.

      One of the most robust features of the ADO.NET DataSet is that you can store multiple related rowsets using DataTable and DataRelation objects as well as the original values and changes to them. Through the DataSet, an application can have a parent-child relationship represented by a single data store. This allows the application to store changes locally to both the parent and the child rowsets in the DataSet. The DataSet's changes can be cached locally and then later saved to a database all at once. For example, through a front-end application, a user could make changes to data, including deletions, updates, the addition of new records, and the addition of detail records. The changes would be cached locally and then could either be canceled entirely or sent back to the database all in one transaction.

       In the Data Points column in the July 2003 issue of MSDN® Magazine I focused on managing batch inserts from a DataSet, detailing how to maintain the integrity of the parent-child relationship and IDENTITY values. This month I'll demonstrate how to manage inserts, updates, and deletes from both parent and child tables all in one batch. Using the Orders and [Order Details] tables of the SQL Server™ Northwind database, I'll walk through a sample application that can manipulate several Order and Order Detail records, storing changes in a relational ADO.NET DataSet that contains DataTable objects. The DataSet will be stored locally and only its changes will be marshaled to a business services object. I will discuss how to enforce and relax constraints on the DataSet, the SqlDataAdapter's RowUpdated event handler, how to implement transactions via ADO.NET, and how to merge DataSets together. I will also discuss one of the most critical factors in saving all types of changes from a hierarchical DataSet: the sequence in which the action queries are executed against the database.

详细请看MSDN

http://msdn.microsoft.com/en-us/magazine/cc188728.aspx
posted @ 2012-07-14 22:12  simplefrog  阅读(207)  评论(0编辑  收藏  举报