The ADO.NET DataAdapter class

When you need to extract records from a database and use them to fill a table in a DataSet, you should use ADO.NET object: DataAdapter. Because the DataAdapter comes in a provider-specific object there is separate class for each provider: SqlDataAdapter, OracleDataAdapter, and so on. The DataAdapter works as a bridge between a single DataTable in the DataSet and the data source. It contains all the available commands for querying and updating the data source. You can enable the DataAdapter to edit, delete and add rows by specifying Command objects for the UpdateCommand, DeleteCommand, and InsertCommand properties of the DataAdapter. You can use the DataAdapter to fill a DataSet by setting the SelectCommand.

Three key methods provided by the DataAdapter are listed in the next table:




Adds a DataTable to a DataSet by executing the query in the SelectCommand. If your query returns multiple result sets, this method will add multiple DataTable objects at once. You can also use this method to add data to an existing DataTable.


Adds a DataTable to a DataSet by executing the query in the SelectCommand and retrieving schema information only. This method doesn’t add any data to the DataTable. Instead, it simply preconfigures the DataTable with detailed information about column names, data types, primary keys, and unique constraints.


Examines all the changes in a single DataTable and applies this batch of changes to the data source by executing the appropriate InsertCommand, UpdateCommand, and DeleteCommand operations.


The next picture shows how a DataAdapter and its Command objects work together with the data source and the DataSet. You can find more details about DataSet from the article The ADO.NET DataSet class:


Interaction between the DataAdapter and the data source

Interaction between the DataAdapter and the data source