Can you explain the difference between a DataReader, a DataAdapter, a Dataset, and a DataView?

Technology CommunityCategory: ADO.NETCan you explain the difference between a DataReader, a DataAdapter, a Dataset, and a DataView?
VietMX Staff asked 3 years ago
  • DataReader is a forward-only iterator over a set of results. It’s usually the most efficient way to deal with records when you don’t need random access (in other words you can’t go backwards). It is “scalable” to any number of records, at least in terms of memory pressure, since it only loads one record at a time. One typical way to get a DataReader is by using the ExecuteReader method of a DbCommand.
  • DataSet represents a set of DataTable objects. More often than not, it will just contain one table, but if you do a query with multiple SELECT statements, the DataSet will contain a table for each. Because this is an in-memory representation, you have to be careful about how much data you pull into a DataSet. You can “Fill” a DataSet using the Fill method of a DataAdapter.
  • DataAdapter is a kind of “pipe” that funnels data from a DB engine into a DataSet. That’s why you’ll have one DataAdapter implementation for each DB provider type. One DataSet, many providers.
  • DataView is like a virtual subset of a DataTable.