Different Between DataReader, DataAdapter, DataSet, DataView and DataTable

What is the main different between DataReader, DataAdapter, DataSet and DataTable in ADO.NET architecture? When this object will be used?

Here is the simple explanation on it.

  • DataReader – The datareader is a forward-only, readonly stream of data from the database. This makes the datareader a very efficient means for retrieving data, as only one record is brought into memory at a time. The disadvantage: A connection object can only contain one datareader at a time, so we must explicitly close the datareader when we are done with it. This will free the connection for other uses. The data adapter objects will manage opening and closing a connection for the
    command to execute
  • DataAdapter – Represents a set of SQL commands and a database connection that are used to fill the DataSet and update the data source. It serves as a bridge between a DataSet and a data source for retrieving and saving data. The DataAdapter provides this bridge by mapping Fill, which changes the data in the DataSet to match the data in the data source, and Update, which changes the data in the data source to match the data in the DataSet. By using it, DataAdapter also automatically opens and closes the connection as and when required.
  • DataSet – The DataSet is the centerpiece of a disconnected, data-driven application; it is an in-memory representation of a complete set of data, including tables, relationships, and constraints. The DataSet does not maintain a connection to a data source, enabling true disconnected data management. The data in a DataSet can be accessed, manipulated, updated, or deleted, and then reconciled with the original data source. Since the DataSet is disconnected from the data source, there is less contention for valuable resources, such as database connections, and less record locking.
  • DataView – A major function of the DataView is to allow for data binding on both Windows Forms and Web Forms. Usually, a DataView data component is added to the project to display a sub-set of the records in a DataSet or DataTable. It also acts as filtered and sorted view of data to the DataTable.
  • DataTable – Represents one table of in-memory data. A DataTable stores data in a similar form to a database table: data is stored in a set of fields (columns) and records (rows). The DataTable class is a central class in the ADO.NET architecture; it can be used independently, and in DataSet objects. A DataTable consists of a Columns collection, a Rows collection, and a Constraints collection. The Columns collection combined with the Constraints collection defines the DataTable schema, while the Rows collection contains the data.