Databases Reference
In-Depth Information
CHAPTER 13
Using Datasets and
Data Adapters
I n Chapter 12, you saw how to use data readers to access database data in a connected,
forward-only, read-only fashion. Often, this is all you want to do, and a data reader suits
your purposes perfectly.
In this chapter, you'll look at a new object for accessing data, the dataset . Unlike data
readers, which are objects of data provider-specific classes that implement the System.
Data.IDataReader interface, datasets are objects of the class System.Data.DataSet , a distinct
ADO.NET component used by all data providers. Datasets are completely independent of
and can be used either connected to or disconnected from data sources. Their funda-
mental purpose is to provide a relational view of data stored in an in-memory cache.
n Note In yet another somewhat confusing bit of terminology, the class is named DataSet , but the generic
term is spelled dataset (when one expects data set). Why Microsoft does this is unclear, especially since data
set is the more common usage outside ADO.NET. Nonetheless, we'll follow the .NET convention and call
DataSet objects datasets.
So, if a dataset doesn't have to be connected to a database, how do you populate it
with data and save its data back to the database? This is where data adapters come in.
Think of data adapters as bridges between datasets and data sources. Without a data
adapter, a dataset can't access any kind of data source. The data adapter takes care of all
connection details for the dataset, populates it with data, and updates the data source.
In this chapter, we'll cover the following:
• Understanding the object model
• Working with datasets and data adapters
• Propagating changes to a data source
265
Search WWH ::




Custom Search