CHAPTER 22 ADO.NET PART II: THE DISCONNECTED LAYER
Table 22-8. Core Members of the DbDataAdapter Class
Members
Meaning in Life
Fill()
Executes a SQL SELECT command (as specified by the SelectCommand
property) to query the database for data and loads the data into a
DataTable.
SelectCommand
InsertCommand
UpdateCommand
DeleteCommand
Establishes the SQL commands that you will issue to the data store when
the Fill() and Update() methods are called.
Update()
Executes SQL INSERT, UPDATE, and DELETE commands (as specified by
the InsertCommand, UpdateCommand, and DeleteCommand properties) to
persist DataTable changes to the database.
Notice that a data adapter defines four properties: SelectCommand, InsertCommand, UpdateCommand,
and DeleteCommand. When you create the data adapter object for your particular data provider (e.g.,
SqlDataAdapter), you can pass in a string that represents the command text used by the SelectCommand’s
command object.
Assuming each of the four command objects has been properly configured, you can then call the
Fill() method to obtain a DataSet (or a single DataTable, if you so choose). To do so, you have the data
adapter execute the SQL SELECT statement specified by the SelectCommand property.
Similarly, if you want to persist a modified DataSet (or DataTable) object back to the database, you
can call the Update() method, which will use any of the remaining command objects, based on the state
of each row in the DataTable (you’ll learn more about this in a bit).
One of the strangest aspects of working with a data adapter object is the fact that you are never
required to open or close a connection to the database. Rather, the underlying connection to the
database is managed on your behalf. However, you will still need to supply the data adapter with a valid
connection object or a connection string (which you will use to build a connection object internally) to
inform the data adapter exactly which database you want to communicate with.
Note A data adapter is agnostic by nature. You can plug in different connection objects and command objects
on the fly and fetch data from a diverse variety of databases. For e