08.01.2015 Views

Beginning Web Development, Silverlight, and ASP.NET AJAX

Beginning Web Development, Silverlight, and ASP.NET AJAX

Beginning Web Development, Silverlight, and ASP.NET AJAX

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

70<br />

CHAPTER 4 ■ DATA BINDING WITH <strong>ASP</strong>.<strong>NET</strong><br />

of maintaining state between the tiers of your application can be much higher, as you<br />

may be passing large amounts of data (sometimes referred to as data sets) between them.<br />

Thus, ADO.<strong>NET</strong> offers a disconnected model that enables you to access data from<br />

another tier, disconnect from that tier (thus breaking state), <strong>and</strong> access that data locally.<br />

To prevent data from being corrupted, ADO.<strong>NET</strong> provides the means for syncing back up<br />

with the data store when your transaction is complete, as well as locking mechanisms to<br />

prevent other processes from affecting the data while your application is holding it in a<br />

disconnected state.<br />

At the heart of the disconnected model is XML. ADO.<strong>NET</strong> was designed with the<br />

XML classes of the .<strong>NET</strong> Framework in mind, <strong>and</strong> at the core of this is the DataSet object,<br />

which you’ll undoubtedly encounter if you continue writing ADO.<strong>NET</strong>-based applications.<br />

(It’s also used under the covers when controls are automatically bound to a<br />

database, although that’s not obvious at a casual glance.)<br />

Using ADO.<strong>NET</strong><br />

You use a .<strong>NET</strong> data provider to connect to the data store. A provider is one or more<br />

classes that give you programmatic access to a database, providing methods that enable<br />

you to read or update data stored in the supported data store. The main classes that you’ll<br />

use when using a data provider to connect to databases are as follows:<br />

Connection: As its name suggests, the Connection class is used to make <strong>and</strong> manage<br />

the connection with the database.<br />

Comm<strong>and</strong>: You use Comm<strong>and</strong> to create <strong>and</strong> execute Structured Query Language (SQL)<br />

statements against your database, or to access stored procedures already on the<br />

database <strong>and</strong> execute them.<br />

DataReader: When you want to access data in a read-only manner, moving forward<br />

through the data as you read, this class provides a lightweight, fast component that<br />

achieves this.<br />

DataAdapter: The DataAdapter class is used to facilitate the communication between<br />

the disconnected DataSet <strong>and</strong> the data store. It fills the DataSet with data <strong>and</strong> provides<br />

the methods to apply changes to the data stored within the data store based<br />

on any modifications made within the (disconnected) DataSet.<br />

DataSet: The DataSet is a disconnected representation of all or part of a database. It is<br />

much more sophisticated than something like a recordset or table because it can<br />

support a collection of tables, relationships, constraints, <strong>and</strong> more.<br />

ADO.<strong>NET</strong> supplies you with a number of built-in providers, including a SQL Server<br />

provider that is optimized for SQL Server. This includes all of the preceding classes

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!