Вы находитесь на странице: 1из 28

ADO.NET (ActiveX Data Object for .

NET) It is a set of computer software components that programmers can use to access data and data services. It is a part of the class library that is included with the Microsoft .NET Framework It is commonly used by programmers to access and modify data stored in relational database systems, though it can also access data in non-relational sources.

Where does ADO sit in .NET Framework ?


VB C# C++ Jscript Visual Studio .NET

Common Language Specification ASP.Net ADO.Net Base Class Library Common Language Runtime (CLR) Windows Forms XML.Net

Windows

COM+ Services

ADO.NET is sometimes considered an evolution of ActiveX Data Objects (ADO) technology, but was changed so extensively that it can be considered an entirely new product. Microsoft's ActiveX Data Objects (ADO) is a set of Component Object Model (COM) objects for accessing data sources. ActiveX is a framework for defining reusable software components in a programming language-independent way.
ADO.NET uses a disconnected architecture to operate.

ADO.NET is conceptually divided into consumers and data providers. The consumers are the applications that need access to the data. The providers are the software components that implement the interface and thereby provide the data to the consumer.

ADO.NET Namespaces
System.data Core namespace, defines types that represent data
Types shared between managed providers Types that allow connection to OLE DB compliant data sources Types that are optimized to connect to Microsoft SQL Server

System.Data.Common

System.Data.OleDb

System.Data.SqlClient

System.Data.SqlTypes

Native data types in Microsoft SQL Server

ADO.NET Architecture
ADO.NET maintains a disconnected database access model which means, when an application interacts with the database, the connection is opened to serve the request of the application and is closed as soon as the request is completed. The ADO.NET components have been designed to factor data access from data manipulation.

Data Access in ADO.NET relies on two components: DataSet and the .NET Framework data provider. NET Framework data provider is a set of components including the Connection, Command, DataReader, and DataAdapter objects. DataSet consists of a collection of DataTable objects that relate to each other with DataRelation objects.

Data Provider
The Data Provider is responsible for providing and maintaining the connection to the database. A DataProvider 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 DataProviders: the SQL Data Provider which is designed only to work with Microsoft's SQL Server 7.0 or later and the OleDb DataProvider which allows us to connect to other types of databases like Access and Oracle

Each DataProvider consists of the following component classes: The Connection object The Command object The DataReader object The DataAdapter object

Data provider

Connection The Connection object creates the connection to the database. Microsoft Visual Studio .NET provides two types of Connection classes: the SqlConnection object, which is designed specifically to connect to Microsoft SQL Server 7.0 or later. the OleDbConnection object, which can provide connections to a wide range of database types like Microsoft Access and Oracle. The Connection object contains all of the information required to open a connection to the database.

Command Command objects are used to execute commands to a database across a data connection. The Command objects can be used to execute stored procedures on the database, SQL commands, or return complete tables directly.

The Command object is represented by two corresponding classes: SqlCommand OleDbCommand

Command objects provide three methods that are used to execute commands on the database: ExecuteNonQuery: Executes commands that have no return values such as INSERT, UPDATE or DELETE ExecuteScalar: Returns a single value from a database query ExecuteReader: Returns a result set by way of a DataReader object

DataReader Object The DataReader provides a highperformance stream of data from the data source. It provides fast, forward-only, read-only access to query results. Its fastest way to retrieve records from a data source because its direction is limited to forward-only, it provides great performance for programmatically processing results.

DataAdapter provides four properties that represent database commands: SelectCommand InsertCommand DeleteCommand UpdateCommand When the Update method is called, changes in the DataSet are copied back to the database

DataAdapter Object DataAdapter provides a bridge between the DataSet and the data source. It is essentially the middleman facilitating all communication between the database and a DataSet. The DataAdapter is used either to fill a DataTable or DataSet with data from the database with it's Fill method. After the memory-resident data has been manipulated, the DataAdapter can commit the changes to the database by calling the Update method.

DataSet Object
The dataset is a disconnected, in-memory representation of data(results sets from Data Source). It can be considered as a local copy of the relevant portions of the database. The DataSet is persisted in memory and the data in it can be manipulated and updated independent of the database. The data in DataSet can be loaded from any valid data source like Microsoft SQL server database, Microsoft Access database.

DataSet represents a cache of data which is completely independent from the Data Source. DataSet consists of a collection of DataTable objects that can relate to each other with DataRelation objects. The DataTable contains a collection of DataRow and DataCoulumn Objects which contains Data.

DataSet

ADO.NET Classes ADO.NET also contains some database specific classes. Microsoft itself has provided the specialized and optimized classes for their SQL server database system. The names of these classes start with 'Sql' and are contained in the System.Data.SqlClient namespace Microsoft has also provided the general classes which can connect application to any OLE supported database server. The name of these classes start with 'OleDb' and these are contained in the System.Data.OleDb namespace.

Class SqlConnection, OleDbConnection SqlCommand, OleDbCommand

Description Represents a connection to the database system Represents SQL a query

SqlDataAdapter, A class that connects to the database system, OleDbDataAdapter fetches the records and fills

SqlDataReader, OleDbDataReader SqlParameter, OleDbParameter

A stream that reads data from the database in a connected design Represents a parameter to a stored procedure

Accessing Data using ADO.NET


Data access using ADO.NET involves the following steps:
Defining the connection string for the database server Defining the connection (SqlConnection or OleDbConnection) to the database using a connection string Defining the command (SqlCommand or OleDbCommand) or command string that contains the query

Defining the Data Adapter (SqlDataAdapter or OleDbDataAdapter) using the command string and the connection object Creating a new DataSet object If the SQL command is SELECT, filling the DataSet object with the results of the query through the Data Adapter Reading the records from the DataTables in the DataSets using the DataRow and DataColumn objects If the SQL command is UPDATE, INSERT or DELETE, the dataset will be updated through the data adapter Accepting to save the changes in the DataSet to the database

Benefits of ADO.NET Interoperability and security through use of XML

Open standard for data that describes itself


Human readable and decipherable text Used internally but accessible externally Can use XML to read and write and move data Scalability through the disconnected DataSet

Comparison of ADO and ADO.NET


ADO ADO.N ET

Business Model

Connection-oriented Models used mostly

Disconnected models are used: Message-like Models.

Disconnected Provided by Data Provided by Record set Access Adapter and Data set XML Support Limited Robust Support

Comparison of ADO and ADO.NET


ADO ADO.N ET

Connection Model

Client disconnected as Client application needs soon as the data is to be connected always processed. DataSet is to data-server while disconnected at all working on the data. times. ADO objects ADO.NET uses XML for communicate in binary passing the data. mode.

Data Passing

Comparison of ADO and ADO.NET


ADO Derives information about data implicitly Design-time at run time, based on support metadata that is often expensive to obtain. ADO.NET

Provides better runtime performance and more consistent runtime behavior.

Questions or Comments ?

Вам также может понравиться