In order to better support the disconnected model, ADO.NET components separate data access from data processing. This operation is accomplished through two main components: DataSet and .NET Framework data provider. The following diagram illustrates the concept of separation of data access and data processing.
DataSet is ADO. The core component of the disconnected architecture of N ET is used for data access, but has nothing to do with the specific data source. Therefore, it can be used for a variety of different data sources and ML data, and even used to manage the application's local data, such as data cached in memory. The DataSet contains a collection, which contains one or more DataTable objects composed of row and column data, as well as primary key codes, foreign key codes, constraints, and relationship information of data in the DataTable object. DataSet is essentially a database in memory, it does not need to care about the source of the data. Data can come from database, XML. file. It even comes from both or somewhere else. No matter where the data source is located, you can first perform insert, update, and delete operations on the DataSet, and then save the changes to the data source. This chapter will discuss the DataSet object family in depth later in this chapter.
Another core element of the ADO.N ET architecture is the .NET Data Provider, and its components are used for data processing (corresponding to the data access function of the DataSet).
The following table summarizes the four core objects that make up the .NET Framework data provider.
Object | description |
---|---|
Connection |
Establish a connection with a specific data source. Connection The base class of all objects is DbConnection class. |
Command |
Execute commands on the data source. Open Parameters and can be executed within the Transaction scope Connection . Command The base class of all objects is the DbCommand class. |
DataReader |
Read only forward and read-only data streams from the data source. DataReader The base class of all objects is DbDataReader class. |
DataAdapter |
Use data sources to populate DataSet and resolve updates. DataAdapter The base class of all objects is DbDataAdapter class. |
The DataAdapter uses Command objects to execute SQL commands on the data source, load data into the DataSet, and return the adjusted data in the DataSet to the data source.
The data provider included in the .NET Framework.
.NET Framework data provider — .NET Framework data provider | description |
---|---|
.NET Framework data provider for SQL Server | Provide data access to Microsoft SQL Server. Use the System.Data.SqlClient namespace. |
.NET Framework data provider for OLE DB | Provides access to data from data sources exposed using OLE DB. Use the System.Data.OleDb namespace. |
.NET Framework data access interface for ODBC | Provides access to data from data sources exposed using ODBC. Use the System.Data.Odbc namespace. |
.NET Framework data access interface for Oracle | Suitable for Oracle data sources. The .NET Framework data provider for Oracle supports Oracle client software version 8.1.7 and later, and uses the System.Data.OracleClient namespace. |
EntityClient provider | Provides data access to Entity Data Model (EDM) applications. Use the System.Data.EntityClient namespace. |
Data provider for .NET Framework SQL Server Compact 4.0. | Provides data access to Microsoft SQL Server Compact 4.0. Use the System.Data.SqlServerCe namespace. |
The following principles should be followed when choosing a data provider: first choose a relational database management system (RDBMS), if there is a corresponding data provider, use it; if it does not exist, use it. NET OLE DB data provider. Most RDBMS vendors now create their own .NET data providers to encourage .NET developers to use their databases. Finally, if there is no OLE DB data provider, use it. NET ODBC data provider for ODBC access.
Therefore, if the application uses SQL Server, choose the SQL Server .NET data provider. . The NET OLE DB data provider is used to access the data source provided by OLE DB. B These details will be discussed later.