Ado. The main objects in net:
- Connection: Connection object. Used to establish a connection channel from the application to the database server specified database
- Command: Commands object. Used to perform additions and deletions, such as database statement commands
- DataReader: Data reader object. To return data line by row from the database
- DataAdapter: Data adapter object. It encapsulates the batch return data, as well as the operation of adding and deleting data.
- DataSet: Data set object. Used to return data from a database to multiple rows or even tables, as a database in memory
- Parameter: Parameter object. The parameter is represented when a query with parameters is made, or when a stored procedure is called
Two modes of data access:
- Lightweight: Connection + Command + DataReader
- Weight level: Connection + DataAdapter + DataSet
Data provider:
- To access a type of database, you need the provider of that database (Provider)
- The. NET framework directly provides the following four types of provider:
- SQLClient: for accessing SQL Server
- OracleClient: for access to Oracle
- Odbcclient: Used to access ODBC data sources in an ODBC manner
- Oledbclient: For accessing data sources in OLE DB
- Third-party database vendors often provide provider about their own databases. For example, Oracle provides PROVIDER,IBM for MySQL to provide provider for DB2.
- For the provider that accesses SQL Server, the namespace and class name of the corresponding ADO:
|
ADO Object |
Name space |
Class name |
|
Connection |
System.Data.SqlClient |
SqlConnection |
|
Command |
System.Data.SqlClient |
SqlCommand |
|
DataReader |
System.Data.SqlClient |
SqlDataReader |
|
DataAdapter |
System.Data.SqlClient |
SqlDataAdapter |
|
DataSet |
System.Data |
DataSet |
|
Parameter |
System.Data.SqlClient |
SqlParameter |
Database connection:
- To access the database, you must first establish a connection object to the database. The most critical property of a Connection object is the connection string
- Different types of databases, their connection strings are not the same
- Typical SQL Server connection string notation:
-
- Connect to the database with a user name and password:
SERVER=JOE-PC (database server name);d atabase=adventureworks_wroxssrs2012 (database name), Uid=sa (login name);p wd=root (password)
- Connect to the database with Windows authentication:
SERVER=JOE-PC (database server name);d atabase=adventureworks_wroxssrs2012 (database name); Integrated security=true;
ado.net--Basic Concepts