General Overview to .NET Data Sets

The huge mainstream of applications builttoday involve data manipulation in some way-whether it be retrieval,storage, change, translation, verification, or transportation. For anapplication to be scalable and allow other apps to interact with it,the app will need a common mechanism to pass the data around. Ideally,the vehicle that transports the data should contain the base data, anyrelated data and metadata, and should be able to track changes to thedata. Here's where the ADO.NET DataSet steps in. The ADO.NET DataSet isa data construct that can contain several relational rowsets, therelations that link those rowsets, and the metadata for each rowset.The DataSet also tracks which fields have changed, their new values andtheir original values, and can store custom information in its ExtendedProperties collection. The DataSet can be exported to XML or createdfrom an XML document, thus enabling increased interoperability betweenapplications.

When we look at the DataSet object model, wesee that it is made up of three collections; Tables, Relations, andExtendedProperties. These collections make up the relational datastructure of the DataSet. The DataSet.Tables property is aDataTableCollection object, which contains zero or more DataTableobjects. Each DataTable represents a table of data from the datasource. Each DataTable is made p of a Columns collection and a Rowscollection, which are zero or more DataColumns or DataRows, in thatorder.

The Relations property as aDataRelationCollection object, which contains zero or more DataRelationobjects. The DataRelation objects define a parent-child relationshipbetween two tables based on foreign key values. On the other hand, TheExtendedProperties property is a PropertyCollection object, whichcontains zero or more user-defined properties. The ExtendedPropertiescollection can be used contains zero or more user defined properties.This property collection can be used to store custom data related tothe DataSet, such as the time when the DataSet was constructed.

One of the key points to remember about theDataSet is that it doesn't care where it originated. Unlike the ADO 2.xRecordset, the DataSet doesn't track which database or XML document itsdata came from. In this way, the DataSet is a standalone data storethat can be passed from tier to tier in an n-tiered architecture. ThisArticle, we will continue by showing us how to use the DataSet in a.NET-based application to retrieve data, track modifications made bythe user, and send the data back to the database.

Using C# .NET, we will show how to retrieveproducts from the Northwind database from a business servicesapplication and load the information in the presentation tier, allusing .NET. We will walk through examples of how to use the DataSet tosave several rows to the database at one time. The code samples willdemonstrate how to send new rows, changed rows, and deleted rows in onetrip to the business services tier and then on to the database by usinga DataSet.

Twitter Digg Delicious Stumbleupon Technorati Facebook Email

No comments yet... Be the first to leave a reply!