15.02.2015 Views

C# 4 and .NET 4

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

30<br />

Core aDo.neT<br />

WhaT ’ s in This ChaPTer<br />

➤<br />

➤<br />

➤<br />

➤<br />

➤<br />

Connecting to the database<br />

Executing comm<strong>and</strong>s<br />

Calling stored procedures<br />

The ADO.<strong>NET</strong> object model<br />

Using XML <strong>and</strong> XML schemas<br />

This chapter discusses how to access data from your <strong>C#</strong> programs using ADO.<strong>NET</strong>. It shows you<br />

how to use the SqlConnection <strong>and</strong> OleDbConnection classes to connect to <strong>and</strong> disconnect from the<br />

database. You learn the various comm<strong>and</strong> object options <strong>and</strong> see how comm<strong>and</strong>s can be used for each<br />

of the options presented by the Sql <strong>and</strong> OleDB classes, how to call stored procedures with comm<strong>and</strong><br />

objects, <strong>and</strong> how the results of those stored procedures can be integrated into the data cached on the<br />

client. The ADO.<strong>NET</strong> object model is signifi cantly different from the objects available with ADO.<br />

The DataSet , DataTable , DataRow , <strong>and</strong> DataColumn classes are discussed as well as the relationships<br />

between tables <strong>and</strong> constraints that are part of DataSet . The class hierarchy has changed signifi cantly<br />

since the release of the .<strong>NET</strong> Framework 2.0, <strong>and</strong> some of these changes are also described. Finally,<br />

you examine the XML framework on which ADO.<strong>NET</strong> is built.<br />

The chapter begins with a brief tour of ADO.<strong>NET</strong>.<br />

ado . neT oVerVieW<br />

ADO.<strong>NET</strong> is more than just a thin veneer over some existing API. The similarity to ADO is fairly<br />

minimal — the classes <strong>and</strong> methods of accessing data are quite a bit different.<br />

ADO (ActiveX Data Objects) is a library of COM components that has had many incarnations over<br />

the past few years. ADO consists primarily of the Connection , Comm<strong>and</strong> , Recordset , <strong>and</strong> Field<br />

objects. Using ADO, a connection is opened to the database, <strong>and</strong> some data is selected <strong>and</strong> placed<br />

into a record set consisting of fi elds; that data is then manipulated <strong>and</strong> updated on the server, <strong>and</strong> the<br />

connection is closed. ADO also introduced a so - called disconnected record set, which is used when<br />

keeping the connection open for long periods of time is not desirable.<br />

There were several problems that ADO did not address satisfactorily, most notably the unwieldiness<br />

(in physical size) of a disconnected record set. This support was more necessary than ever with the<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!