0
15kviews
Important Classes in ADO.NET.

Mumbai University > information technology > sem 4> Web Programming

Marks: 10M

Year : Dec16

2 Answers
0
185views

ADO.NET Clasess:

ADO.NET provides a bridge between the front end controls and the back end database. The ADO.NET objects encapsulate all the data access operations and the controls interact with these objects to display data, thus hiding the details of movement of data.

The following figure shows the ADO.NET objects at a glance:

enter image description here

1. The DataSet Class:

The dataset represents a subset of the database. It does not have a continuous connection to the database. To update the database a reconnection is required. The DataSet contains DataTable objects and DataRelation objects. The DataRelation objects represent the relationship between two tables.

Following table shows some important properties of the DataSet class:

Properties Description
CaseSensitive Indicates whether string comparisons within the data tables are case-sensitive.
Container Gets the container for the component
DataSet NameGets or sets the name of the current data set.
DefaultViewManager Returns a view of data in the data set.
DesignMode Indicates whether the component is currently in design mode.
EnforceConstraints Indicates whether constraint rules are followed when attempting any update operation.
Events Gets the list of event handlers that are attached to this component.
Extended PropertiesGets the collection of customized user information associated with the DataSet.
HasErrors Indicates if there are any errors.
Namespace Gets or sets the namespace of the DataSet.
Tables Returns the collection of DataTable objects.
Prefix Gets or sets an XML prefix that aliases the namespace of the DataSet.
IsInitialized Indicates whether the DataSet is initialized.
Relations Returns the collection of DataRelation objects.

The following table shows some important methods of the DataSet class:

Methods Description
AcceptChanges Accepts all changes made since the DataSet was loaded or this method was called.
BeginInit Begins the initialization of the DataSet. The initialization occurs at run time.
Clear Clears data.
Copy Copies both structure and data
CreateDataReader() Returns a DataTableReader with one result set per DataTable, in the same sequence as the tables appear in the Tables collection.
CreateDataReader(DataTable[]) Returns a DataTableReader with one result set per DataTable.
EndInit Ends the initialization of the data setEnds
Equals(Object) Determines whether the specified Object is equal to the current Object.
Finalize Free resources and perform other cleanups
GetType Gets the type of the current instance.
GetXML Returns the XML representation of the data.
GetXMLSchema Returns the XSD schema for the XML representation of the data.
oad(IDataReader, LoadOption, DataTable[]) Fills a DataSet with values from a data source using the supplied IDataReader, using an array of DataTable instances to supply the schema and namespace information.
Load(IDataReader, LoadOption, String[]) Fills a DataSet with values from a data source using the supplied IDataReader, using an array of strings to supply the names for the tables within the DataSet.

2. The DataTable Class

The DataTable class represents the tables in the database. It has the following important properties; most of these properties are read only properties except the PrimaryKey property:

Properties Description
ChildRelations Returns the collection of child relationship.
Columns Returns the Columns collection.
Constraints Returns the Constraints collection.
DataSet Returns the parent DataSet.
DefaultView. Returns a view of the table
ParentRelations Returns the ParentRelations collection.
PrimaryKey Gets or sets an array of columns as the primary key for the table.
Rows Returns the Rows collection.

The following table shows some important methods of the DataTable class:

Methods Description
AcceptChanges. Commits all changes since the last AcceptChanges
Clear Clears all data from the table.
GetChanges Returns a copy of the DataTable with all changes made since the AcceptChanges method was called.
GetErrors Returns an array of rows with errors
ImportRows Copies a new row into the table.
Merge Merges the table with another DataTable.
NewRow Creates a new DataRow.
Reset Resets the table to its original state.

3. The DataRow Class

The DataRow object represents a row in a table. It has the following important properties:

Properties Description
HasErrors Indicates if there are any errors.
Items Gets or sets the data stored in a specific column.
Item ArraysGets or sets all the values for the row.
Table Returns the parent table.

The following table shows some important methods of the DataRow class

Methods Description
BeginEdit Begins edit operation.
CancelEdit Cancels edit operation.
Delete Deletes the DataRow.
EndEdit Ends the edit operation.
0
303views

ADO.NET provides a bridge between the front end controls and the back end database. The ADO.NET objects encapsulate all the data access operations and the controls interact with these objects to display data, thus hiding the details of movement of data.

The following figure shows the ADO.NET objects at a glance:

enter image description here

The DataSet class :

The DataSet is the heart of ADO .NET. The DataSet is essentially a collection of DataTable objects; in turn each object contains a collection of DataColumn and DataRow objects. The DataSet also contains a Relations collection, which can be used to define relations between DataTable objects. There is a Constraints collection, which can be used to define unique keys and data validation rules. There are also DataView objects that work hand-inhand with the DataSet. These objects can be used to define filters, sort orders, and display attributes in a given DataTable. You can change from one DataView to another and instantly change the way data is presented to the user. The DataView is part of the data binding mechanism in ADO .NET.

The DataAdapter Class :

The DataAdapter is used to connect DataSets to databases. It is a go-between class. It is comprised of four Command classes and one DataReader class. The DataAdapter is most useful when using data-bound controls in Windows Forms, but it can also be used to provide an easy way to manage the connection between your application and the underlying database tables, views, and stored procedures. Another way of looking at the DataAdapter class is as a way of containing SQL statements and stored procedures for easy programmatic access. All of the SQL needed to maintain a database entity can be contained in a DataAdapter object. The DataAdapter also uses support classes that will create the SQL statements for updating the database from a predefined Select statement, and will fill the parameter collections of the Command objects contained in the class. There is also a wizard that helps create the DataAdapter and another wizard that will create a DataSet from the Command objects contained within the DataAdapter.

DataReader Class :

The DataReader is used to retrieve data. It is used in conjunction with the Command class to execute an SQL Select statement and then access the returned rows. It provides forward-only read-only access to the data. The DataReader is also used by the DataAdapter to pump data into a DataSet when the Fill method of the DataAdapter is called. The DataReader provides high-speed access to data. You can use a DataReader to pull data for web pages that are read-only, reports, graphs or any other application that does not require data binding and only displays data.

Connection Class :

The connection classes provide the means to connect to the database. They also manage transactions, and connection pooling. In addition, they are used to manage transaction objects. The five main members of this class are ConnectionString, Open, Close, and BeginTransaction. The various parameters for connecting to a database are set via the ConnectionString property. In previous versions of ADO, most of the ConnectionString values were exposed through properties. For security reasons, ADO .NET only exposes the ConnectionString

Command Class :

The Command class provides methods for storing and executing SQL statements and stored procedures. It has a Parameters collection that is used to pass parameters into and out of stored procedures. The collection can also be used to set the parameters for a parameterized SQL statement. The DataAdapter class contains four Command classes for selecting, updating, inserting, and deleting data. The class can also be used by itself for non-databound access to the database. Of all the ADO .NET classes, the Command class is the closest to the ADO Command class in functionality and remains essentially unchanged as far as properties and methods go. Of course, it is a .NET Framework class and does not use COM at all. It also has some enhancements over the old ADO Command object.

Please log in to add an answer.