Thursday, January 5, 2012

What is ADO.NET?




What is ADO.NET?


<!--> Normal 0 false false false EN-US X-NONE X-NONE

ADO.NET, an object oriented data access technology,

ADO.NET is collection of classes used to communicate between an application and a database.

Components of ADO.NET Architecture

The two basic components of this architecture are:

1. Data Provider

2. Dataset

Data Provider

The Data Provider is responsible for providing and maintaining the connection to the database.

A Data Provider is a set of related components that work together to provide data in an efficient and performance driven manner.

The .NET Framework currently comes with two Data Providers:

1. SQL Data Provider which is designed only to work with Microsoft's SQL Server 7.0 or later

2. OleDb Data Provider which allows us to connect to other types of databases like Access and Oracle.

Each Data Provider consists of the following component classes:

1. Connection

2. Command

3. DataReader

4. DataAdapter

The Connection object which provides a connection to the database
The Command object which is used to execute a command (Sql query, stored procedure)
The DataReader object which provides a forward-only, read only, connected recordset
The DataAdapter object which populates a disconnected DataSet with data and performs update

Connection

The Connection object establishes a connection to the database using the user name, password and the database name as parameters. The following are the supported Connection classes:

1. OleDbConnection

2. OdbcConnection

3. OracleConnection

4. SqlConnection

Command

The Command object is used to send the SQL Statements to the database.

Commands are used to insert data, retrieve data and execute stored procedures in the database. The following are the methods of the Command class:

1. ExecuteScalar

2. ExecuteReader

3. ExecuteNonQuery

4. ExecuteXmlReader

The ExecuteScalar method returns a single value from a query. This is faster compared to using ExecuteReader and is the preferred choice to retrieve a single value from a database table.

The ExecuteReader method returns a single record at a time.

The ExecuteNonQuery is used to change the state of a table. It can be used to insert, update or delete records from the table. ExecuteNonQuery can also be used to execute stored procedures.

The ExecuteXmlReader method returns an XmlReader object.

The ExecuteNonQuery method returns an integer representing the number of rows affected in the operation.

DataReader

A DataReader is a connected, forward only, read only stream of data that is retrieved from the database. The DataReader requires an open connection so it works in the connected mode.

DataReader objects cannot be directly instantiated. Rather, the DataReader is returned as the result of the Command object's ExecuteReader method. The SqlCommand.ExecuteReader method returns a SqlDataReader object, and the OleDbCommand.ExecuteReader method returns an OleDbDataReader object.

The DataReader can provide rows of data directly to application logic when you do not need to keep the data cached in memory. Because only one row is in memory at a time, the DataReader provides the lowest overhead in terms of system performance but requires the exclusive use of an open Connection object for the lifetime of the DataReader.

A DataReader is much faster compared to the disconnected DataSet, but it does require an open available connection.

DataAdapter

The DataAdapter is a bridge between the DataSet and the database.

It provides a set of methods and properties to move data to and from between a database and its in-memory representation, the DataSet.

It is also used to update the data in the database with the data in the DataSet. The following are two of the most important methods of the DataAdapter class:

1. Fill

2. Update

The DataAdapter is used either to fill a DataSet or Data Table with data from the database with its Fill method.

The Update method of the DataAdapter class commits the changes back to the database.

The DataAdapter provides the following commands:

1. SelectCommand

2. InsertCommand

3. UpdateCommand

4. DeleteCommand

DataSet

1. A DataSet is an in-memory, disconnected representation of the database.

2. It can be considered as a local copy of the relevant portions of the database.

3. The DataSet is persisted in memory and the data in it can be manipulated and updated independent of the database.

4. When the use of this DataSet is finished, changes can be made back to the central database for updating.

5. The data in DataSet can be loaded from any valid data source like Microsoft SQL server database, an Oracle database or from a Microsoft Access database.

6. The following are some of its features:

Disconnected

Tracks changes to the data

XML support

Caches Data locally




for more inquiry about classes call @9619979219

0 comments:

Post a Comment

Followers

 

Teaching Dot Net. Copyright 2012 All Rights Reserved

Managed By Abhishek Pathak