Applications and Components of the DataSet

Applications and Components of the DataSet

The DataSet is the key object in ADO.NET. It is a universal container for data, regardless of the actual source of the data. The DataSet and its associated objects offer a relational view of data, although it can also load or save its data and/or schema information as XML. The DataSet provides an explicit in-memory data model that is always fully disconnected from the data source and can easily be passed between address spaces and machines.

Typical applications and uses for the DataSet include the following.

  • Application data The DataSet is a simple and flexible object for use in storing local application data. Accessing the data is as easy as accessing data in an array, but the DataSet also provides advanced features such as sorting and filtering.

  • Remoting data The DataSet automatically uses XML to marshal (transfer) data from one computer to another. This capability greatly eases the development of applications with Web Services, SOAP, or low-level remoting.

  • Caching data The DataSet can cache data during development of ADO.NET or other types of distributed applications, avoiding multiple across-the-network hits.

  • Persisting data The DataSet provides methods to save its data and schema information in standard XML formats.

  • User interaction The DataSet effectively supports user interaction for different GUIs by combining its sorting, filtering, and scrolling capabilities with the ability to bind different views of the data to both Windows and Web Forms.

The data in a DataSet is organized in one or more DataTables. Each DataTable is ignorant of the source of the data it contains, which implies that the DataSet and DataTables are always disconnected from the data source. The DataSet merely contains multiple data tables and provides for the data to be manipulated, transported, or bound to user interface controls. Figure 5.1 shows the DataSet and its subsidiary objects.

Figure 5.1. The DataSet and its subsidiary objects

graphics/05fig01.jpg

These subsidiary objects may be described as follows.

  • DataTable Each DataTable contains collections of DataRow, DataColumn, and Constraint objects, along with collections of DataRelation objects linking to other parent and child tables. The view of data offered by the DataTable is similar to that of the ADO 2.X record set.

  • DataColumn The DataColumn object is the basic unit for retrieving or defining the schema definition for a DataTable. It contains the specific information for each column (field) in the DataTable, including name, data type, and other attributes, such as the Unique, ReadOnly, AllowDBNull, and AutoIncrement properties. It also has an Expression property, which allows you to calculate the value for a column or to create an aggregate column.

  • DataRow The DataRow object represents a single record in the DataTable and is the object used to add, retrieve, and/or modify data in the DataTable. You can navigate the Rows collection of a DataTable sequentially or by direct access to specific rows.

  • DataRelation The DataRelation object defines a relationship between two tables in a DataSet. It represents a classic parent-child or primary key-foreign key link between rows of data in the two tables. You navigate the relations between the tables by means of the ChildRelations and ParentRelations collections (of DataRelation objects) of the DataTable object.

  • Constraint The Constraint object defines a rule that can be enforced to ensure the integrity of the data in the DataTable. It includes the familiar UniqueConstraint, which ensures that all values within the table are unique, and a ForeignKeyConstraint, which determines the action to be taken on rows in the related table. The defined constraint can include one or more DataColumns. Each DataTable has a Constraints property, which is a collection of constraints for that table.



Database Access with Visual Basic. NET
Database Access with Visual Basic .NET (3rd Edition)
ISBN: 0672323435
EAN: 2147483647
Year: 2003
Pages: 97

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net