DataAdapter
| DataAdapter | |
|---|---|
| Developer | Microsoft |
| Repository |
|
| Written in | C# (reference implementation) |
| Engine | |
| Platform | .NET Framework, .NET |
| Included with | System.Data/System.Data.Common |
| Type | Data access component (ADO.NET) |
In ADO.NET, a data adapter (DataAdapter) is an object that acts as a bridge between a data source and a disconnected in-memory data representation such as a DataSet, enabling data to be retrieved into the DataSet and later written back to the data source.[1][2]
Overview
[edit | edit source]The DataAdapter is an abstract base class in the System.Data.Common namespace; provider-specific implementations (such as for SQL Server, OLE DB, or ODBC) typically derive from DbDataAdapter.[1][3] Data adapters are used with the ADO.NET disconnected model, where an application loads data into a memory-resident DataSet (including related tables, constraints, and relationships) and later reconciles changes back to the underlying data source.[4]
Operation
[edit | edit source]Filling a DataSet
[edit | edit source]A DataAdapter populates a DataSet (or DataTable) through its Fill method, using its SelectCommand to retrieve rows from the data source.[5]
Updating the data source
[edit | edit source]A DataAdapter can persist changes made in the DataSet back to the data source using Update; it applies INSERT, UPDATE and DELETE operations as appropriate based on changes tracked in the DataSet, using command objects such as InsertCommand, UpdateCommand and DeleteCommand.[6]
Schema and table mappings
[edit | edit source]Data adapters can also configure a DataSet's schema from the data source (for example, using FillSchema) and can map source table names to DataTable names through table mappings.[7][3]
Implementations
[edit | edit source]Provider-specific data adapters include:
- SqlDataAdapter for Microsoft SQL Server (System.Data.SqlClient)[8]
- OleDbDataAdapter for OLE DB data sources (System.Data.OleDb)[9]
- OdbcDataAdapter for ODBC data sources (System.Data.Odbc)[10]
A DataSet can be filled and updated using multiple DataAdapter instances, and can contain related tables originating from different data sources exposed through different providers.[11]
See also
[edit | edit source]References
[edit | edit source]- ^ a b Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
- ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
- ^ a b Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
- ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
- ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
- ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
- ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
- ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
- ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
- ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
- ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).