In this tutorial you will learn about The ADO .NET Object Model, Data Providers and Their Objects and the Dataset Objects
Access and Manipulate Data – The ADO .NET Object Model
The ADO .NET Object Model
ADO .NET renders very good support for working with disconnected data. ADO .NET 2.0 comes with additional features that enhance the performance of common database tasks. The data source window provides a centralized window for creating and configuring related objects required to access a date source. Smart tags added to the controls provide fast access to common development tasks. However all the functionalities of the ADO .NET 1.1 have also not been discarded.
.
.
.
Data Providers and Their Objects
ADO .NET is offers a highly sophisticated system to support data centric application development. The data binding in Windows Forms enables users access data from databases as well as other structures like arrays and collections. Users can bind to a wide variety of structures, from simple arrays to complex data rows and views. However, any bindable structure must support IList interface. Any object that supports IList should be capable of being bound. We shall see some of the objects that provide data.
-
DataColumn object – This is the building block of the DataTable. A number of such objects make up a table. Each DataColumn object has a DataType property that determines the kind of data that the column is holding. A control can be bound simply such as a TextBox to a column within a data table
.
-
Data Table – A DataTable object is the representation of a table, with rows and columns, in ADO .NET. A DataTable can be considered to a collection of two kinds viz., DataColumn objects and DataRows object. You can complex-bind a control to the information contained in a data table. Controls like DataGrid are used for this purpose
.
-
DataView object – A DataView object is a customized view of a single data table that may be filtered or sorted. A data view is the data snapshot used by complex-bound controls. You can simple-bind or complex-bind to the data within the DataView. This is not an updating data source
.
-
DataSet object – A DataSet is a collection of tables, relationships and constraints. You can simple-bind or complex bind to the data within the dataset.
.
-
DataViewManager Object – A DataViewManager object is a customized view of the whole DataSet. It is an extended form of a DataView with realations included and with multiple tables.
The DataSet Objects
DataSets in ADO .NET are objects that store data in a memory cache, allowing access to the data even with the application disconnected from the databases. The structure of a System.Data.DataSet is similar to that of a relational database. It is organized in a hierarchical object mode of tables, rows, columns, constraints, and relationships.
A DataSet can be typed or untyped. Typed DataSets derive its table and column structure from a schema ( .XSD) file and is easier to program. Either a typed or untyped dataset can be used in applications. ADO .NET gives better support to typed datasets. A DataSet is located in System.Data NameSpace. DataSets are memory structures that do not contain any data by default. DataSets will have to be filled with data. This can be done in several ways.
1) If the DataSet was created using design-time tools, you can call the fill method of a TableAdapter. TableAdapters are created with a default Fill method but you can change the name.
2) By calling the Fill method of DataAdapter
3) Manually populate the DataSets by creating DataRow objects and call the AddNew method
4) Read an XML Document or stream into the dataset.
5) Copy the contents of one DataSet with another.
6) Copy the contents of one DataTable into a DataSet
A DataSet can store not only the data but also information about the data such as original, modified, inserted and deleted. Update of the underlying data-store is also possible. This can be done by calling the Update method of the TableDataAdapter or DataAdapter
A DataSet is typically a disconnected data-store. It does not support the idea of a current record. All the records in the DataSet are available at any time. You can access any row at any time directly. If the data is bound to one or more controls you can use the BindingNavigator to traverse the records. Some of the features of the DataSets that are based on XML.
1. The structure of a DataSet can be defined in an XML schema
2. You can generate a typed DataSet class using the schema information
3. You can read an XML document or stream into a DataSet using the ReadXml file method of DataSet and write to an XML file by calling the WriteXML method of DataSet.
4. You can create an XML view of the contents of a DataSet or DataTable.
Within a DataSet, table and column names are by default case insensitive. In contrast XML documents are case sensitive. The results of a data filter operation may return different data depending up on how the data is interpreted within the DataSet. You can have sufficient control over this by setting the DataSets CaseSensitive property. All tables in the dataset inherit the value of this property by default. This property can be overridden for each individual table by setting the tables CaseSensitive property.
A DataSet is not aware of any or all data relationships that exist in the database. The user can create DataRealtion objects that describe the relations between the tables in the DataSet. Objects of type UniqueConstraint, ForeignKeyConstraint are used to implement constraint.