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. 結果會傳回查詢執行,並會儲存在用戶端上的網路緩衝區中,直到您提出要求時使用讀取方法DataReaderResults 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 資料提供者都有 DbDataReaderDbDataAdapter 物件:.NET Framework Data Provider for OLE DB 包含 OleDbDataReaderOleDbDataAdapter 物件、.NET Framework Data Provider for SQL Server 包含 SqlDataReaderSqlDataAdapter 物件、.NET Framework Data Provider for ODBC 包含 OdbcDataReaderOdbcDataAdapter 物件,而且 .NET Framework Data Provider for Oracle 包含 OracleDataReaderOracleDataAdapter 物件。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 擷取資料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 填入 DataSetPopulating 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.

將現有條件約束新增至 DataSetAdding Existing Constraints to a DataSet
說明如何將現有條件約束加入 DataSetDescribes how to add existing constraints to a DataSet.

DataAdapter DataTable 和 DataColumn 對應DataAdapter DataTable and DataColumn Mappings
說明如何設定 DataTableMappingsColumnMappingsDataAdapterDescribes 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
說明如何使用 DataAdapter,將 DataSet 中的變更解析回資料庫。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