DataAdapter 和 DataReaderDataAdapters and DataReaders

您可以使用 ADO.NET DataReader从数据库中检索只读、只进数据流。You can use the ADO.NET DataReader to retrieve a read-only, forward-only stream of data from a database. 结果将在执行查询时返回,并存储在客户端的网络缓冲区中,直到您使用DataReaderRead方法请求它们。Results are returned as the query executes, and are stored in the network buffer on the client until you request them using the Read method of the DataReader. 使用DataReader可以通过在数据可用时立即检索数据来提高应用程序的性能,并在默认情况下,每次仅在内存中存储一行,从而减少系统开销。Using the DataReader can increase application performance both by retrieving data as soon as it is available, and (by default) storing only one row at a time in memory, reducing system overhead.

DataAdapter 用于从数据源检索数据并填充 DataSet 中的表。A DataAdapter is used to retrieve data from a data source and populate tables within a DataSet. DataAdapter 还可将对 DataSet 所做的更改解析回数据源。The DataAdapter also resolves changes made to the DataSet back to the data source. DataAdapter 使用 .NET Framework 数据提供程序的 Connection 对象连接到数据源,并使用 Command 对象从数据源检索数据以及将更改解析回数据源。The DataAdapter uses the Connection object of the .NET Framework data provider to connect to a data source, and it uses Command objects to retrieve data from and resolve changes to the data source.

随 .NET Framework 提供的每个 .NET Framework 数据提供程序都具有一个 DbDataReader 和一个 DbDataAdapter 对象:用于 OLE DB 的 .NET Framework 数据提供程序包括一个 OleDbDataReader 和一个 OleDbDataAdapter 对象,用于 SQL Server 的 .NET Framework 数据提供程序包括一个 SqlDataReader 和一个 SqlDataAdapter 对象,用于 ODBC 的 .NET Framework 数据提供程序包括一个 OdbcDataReader 和一个 OdbcDataAdapter 对象,用于 Oracle 的 .NET Framework 数据提供程序包括一个 OracleDataReader 和一个 OracleDataAdapter 对象。Each .NET Framework data provider included with the .NET Framework has a DbDataReader and a DbDataAdapter object: the .NET Framework Data Provider for OLE DB includes an OleDbDataReader and an OleDbDataAdapter object, the .NET Framework Data Provider for SQL Server includes a SqlDataReader and a SqlDataAdapter object, the .NET Framework Data Provider for ODBC includes an OdbcDataReader and an OdbcDataAdapter object, and the .NET Framework Data Provider for Oracle includes an OracleDataReader and an OracleDataAdapter object.

本节内容In This Section

使用 DataReader 检索 ADO 数据Retrieving Data Using a DataReader
介绍 ADO.NET DataReader对象,以及如何使用它从数据源返回结果流。Describes the ADO.NET DataReader object and how to use it to return a stream of results from a data source.

从 DataAdapter 填充数据集Populating a DataSet from a DataAdapter
说明如何通过 DataSet 使用表、列和行填充 DataAdapterDescribes how to fill a DataSet with tables, columns, and rows by using a DataAdapter.

DataAdapter 参数DataAdapter Parameters
说明如何与 DataAdapter 的命令属性一起使用参数,包括如何将 DataSet 的列内容映射到命令参数。Describes how to use parameters with the command properties of a DataAdapter including how to map the contents of a column in a DataSet to a command parameter.

将现有约束添加到数据集Adding Existing Constraints to a DataSet
说明如何将现有约束添加到 DataSetDescribes how to add existing constraints to a DataSet.

DataAdapter 数据表和 DataColumn 映射DataAdapter DataTable and DataColumn Mappings
说明如何为 DataTableMappings 设置 ColumnMappingsDataAdapterDescribes how to set up DataTableMappings and ColumnMappings for a DataAdapter.

通过查询结果分页Paging Through a Query Result
提供一个以数据页形式查看查询结果的示例。Provides an example of viewing the results of a query as pages of data.

使用 DataAdapter 更新数据源Updating Data Sources with DataAdapters
说明如何使用 DataAdapterDataSet 中的更改解析回数据库。Describes how to use a DataAdapter to resolve changes in a DataSet back to the database.

处理 DataAdapter 事件Handling DataAdapter Events
说明 DataAdapter 事件以及如何使用这些事件。Describes DataAdapter events and how to use them.

使用 DataAdapter 执行批处理操作Performing Batch Operations Using DataAdapters
说明在从 DataSet 应用更新时,如何通过减少与 SQL Server 之间的往返次数来提高应用程序的性能。Describes enhancing application performance by reducing the number of round trips to SQL Server when applying updates from the DataSet.

请参阅See also