ADO. NET is the next-generation product of Microsoft ActiveX Data Objects (ADO). It is an application development interface (API) for creating Distributed and Data Sharing applications in Microsoft. NET ).
ADO. NET can be used in any user's applications and needs to connect and communicate with the ole db-compliant data source, such as Microsoft SQL Server.
ADO. NET maintains some of the main concepts related to the previous ADO model, which has been greatly improved, obtain structured data from different information sources-a platform text file, data obtained from the database management system, or Hierarchical XML data-however, all are performed according to a compatible and standardized design model.
This article briefly introduces the key features of ADO. NET and focuses on accessing data in Relational Database Management System (rdbms.
Quick browsing
SQL Server 7.0 (and later versions) and any data sources that can be accessed through the OLE DB Provider. These are also known as Managed providers ).. The data access API of the. NET Framework provides two methods to identify and process two types of data sources: SQL Server 7.0 (and updated version) and any data sources that can be accessed through the ole db Provider. SQL (System. data. SQL) database can be directly linked to SQL Server data, while ADO (System. data. ADO) database can be used for any data source accessed through the ole db Provider.
The managed provider of SQL Server uses the dedicated protocol "tabulardata stream" in ms SQL Server 7.0 or later versions, but does not use OLE DB, ADO or ODBC.
Providers managed by ADO. NET can work under these ole db providers.
Driver
Provider
SQLOLEDB
SQL OLE DB Provider
MSDAORA
Oracle ole db Provider
JOLT
Jet ole db Provider
MSDASQL/SQLServer ODBC
SQL Server ODBC Driver via OLE DB for ODBC Provider
MSDASQL/Jet ODBC
Jet ODBC Driver via ole db Provider for ODBC Provider
Currently, ADO. NET does not support MSDASQL/Oracle ODBC Driver (oracle ole db driver for odbc ).
The following sections describe the core components of ADO. NET available for each managed provider.
Connections-connect to and manage database transactions.
Commands -- the command sent to the database.
DataReaders -- directly reads stream data.
DateSets and DateSetCommands -- store and operate data in the resident memory.
The core ADO. NET functions can be summarized as follows:
The Connection object establishes a Connection between the Web page and the database. The Commands object sends a command to the database provider, and the returned results run through these connections as a stream. The result set can be quickly read by DataReaders, stored in a DateSets object in the resident memory, and then accessed and operated records in the dataset through the DateSetCommands object. Developers can use the built-in DateSet method to process datasets on the basic data source.
To use the managed provider in the. NET Framework, You need to include the following namespaces in The. aspx page.
SQL managed provider:
<% @ Import Namespace = "System. Data. SQL" %>
Providers managed by ADO:
<% @ Import Namespace = "System. Data. ADO" %>
Connections
Microsoft provides two Connection objects in the. NET Framework to establish connections to specific databases: SQLConnection and ADOConnection. The Connection object can be explicitly opened on a created Connection by calling the open method. The following code snippet demonstrates how to use any provider to create and open a connection.
SQLConnection
[C #]
String connectionString = "server = localhost; uid = sa; pwd =; database = northwind ";
SQLConnection myConn = new SQLConnection (connectionString );
MyConn. Open ();
[VB]
Dim connectionString As String = _
M connectionString As String = _
"Server = localhost; uid = sa; pwd =; database = northwind"
Dim myConn As SQLConnection = New SQLConnection (connectionString)
MyConn. Open
ADOConnection
[C #]
String connectionString = "Provider = SQLOLEDB.1; Data Source = localhost; uid = sa; pwd =; Initial Catalog = Northwind ;"
ADOConnection myConn = new ADOConnection (connectionString );
MyConn. Open ();
[VB]
Dim connectionString As String = _
Ost; uid = sa; pwd =; Initial Catalog = Northwind ;"
ADOConnection myConn = new ADOConnection (connectionString );
MyConn. Open ();
[VB]
Dim connectionString As String = _
"Provider = SQLOLEDB.1; Data Source = localhost ;"&_
"Uid = sa; pwd =; Initial Catalog = Nohwind"
Dim myConn As ADOConnection = New ADOConnection (connectionString)
MyConn. Open ()
Commands
After the connection is established, the next step is to run the SQL statement on the database. The simplest and most direct method is through ADO and SQL command objects.
The Command object can give the provider instructions on how to operate database information.
A Command can be expressed by a typical SQL statement, including executing select query to return the record set and executing action query) to update (add, edit, or delete) The database records, or to create and modify the table structure of the database. Of course, commands can also pass parameters and return values.
Commands can be clearly defined, or stored procedures in the database can be called. The following code snippet demonstrates how to issue a Select command after a connection is established.
SQLCommand
[C #]
String SQLStmt = "SELECT * FROM MERs ";
SQLCommand myCommand = new SQLCommand (SQLStmt, myConn );
[VB]
Dim SQlStmt As String = "SELECT * FROM MERs"
Dim myCommand As SQLCommand = New SQLCommand (SQLStmt, myConn)
There are two pages in this news. Currently, there are two pages in page 1st.