Tải bản đầy đủ (.pdf) (1,117 trang)

Mastering c sharp database programming

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (8.98 MB, 1,117 trang )

MasteringC#Database
Programming
byJasonPrice ISBN:0782141838
Sybex©2003(665pages)
Thisguidewillhelpyou
understanddatabase
programmingasitprovides
focusedcoverageofADOand
howitrelatestoC#,aswell
asothercomplextopics
includingtransactions,
Windowsforms,WebForms,
XML,andWebServices.
TableofContents
MasteringC#DatabaseProgramming
Introduction
Part1-IntroductiontoADO.NETandDatabases

IntroductiontoDatabaseProgrammingwith
ADO.NET
- IntroductiontoDatabases
- IntroductiontoStructuredQueryLanguage(SQL)
- IntroductiontoTransact-SQLProgramming
- OverviewoftheADO.NETClasses
- IntroducingWindowsApplicationsandADO.NET

Chapter1 Chapter2
Chapter3
Chapter4
Chapter5
Chapter6



Part2-FundamentalDatabaseProgrammingwithADO.NET

Chapter7 - ConnectingtoaDatabase
Chapter8 - ExecutingDatabaseCommands
Chapter9 - UsingDataReaderObjectstoReadResults


Chapter10 - UsingDatasetObjectstoStoreData
Chapter11 - UsingDataSetObjectstoModifyData
Chapter12 - NavigatingandModifyingRelatedData
Chapter13 - UsingDataViewObjects
Part3-AdvancedDatabaseProgrammingwithADO.NET

Chapter14 - AdvancedTransactionControl
Chapter15 - IntroducingWebApplications—ASP.NET
Chapter16 - UsingSQLServer'sXMLSupport
Chapter17 - WebServices
Index
ListofFigures
ListofTables
ListofListings
ListofSidebars


BackCover
C#andADO.NETfacilitatethedevelopmentofanew
generationofdatabaseapplications,includingremote
applicationsthatrunontheWeb.MasteringC#
DatabaseProgrammingistheresourceyouneedto

thriveinthisnewworld.Assumingnopriorexperience
withdatabaseprogramming,thisbookteachesyou
everyaspectofthecraft,fromGUIdesigntoserver
developmenttomiddle-tierimplementation.Ifyou’re
familiarwithearlierversionsofADO,you’llmasterthe
manynewfeaturesofADO.NETallthemorequickly.
You’llalsolearntheimportanceofXMLwithinthenew
.NETparadigm.
CoverageIncludes
AccessingadatabaseusingC#andADO.NET
UsingSQLtoaccessadatabase
UsingVisualStudio.NETtobuildapplications
Creatingandmodifyingdatabasetables
UnderstandingADO.NETclasses
Designing,building,anddeployingWebapplications
thataccessadatabase
Designing,building,anddeployingeffectiveWeb
services
UsingSQLServer’sbuilt-inXMLcapabilities
Workingwithadatabaseinadisconnectedmanner
Usingadvancedtransactioncontrols
UsingTransact-SQLtocreatestoredprocedures
andfunctionsinaSQLServerdatabase
AbouttheAuthor


JasonPriceisanindependentconsultantandwriter,
andisbothaMicrosoftCertifiedProfessionalandan
OracleCertifiedProfessional.Jasonhasmorethan10
yearsofexperienceinthesoftwareindustry,andhe

hasextensiveexperiencewithC#,.NET,andJava.He
istheauthorofMasteringVisualC#.NET,Oracle9i
JDBCProgramming,andJavaProgrammingwith
OracleSQLJ.



MasteringC#DatabaseProgramming
JasonPrice

SanFranciscoLondon
AssociatePublisher:JoelFugazzotto
AcquisitionsEditor:DeniseSantoro-Lincoln
DevelopmentalEditor:TomCirtin
ProductionEditor:EricaYee
TechnicalEditor:AceyBunch
Copyeditor:LauraRyan
Compositor:JillNiles
GraphicIllustrator:JeffWilson,HappenstanceType-O-Rama
Proofreaders:EmilyHsuan,LaurieO'Connell,NancyRiddiough,
MoniquevandenBerg
Indexer:TedLaux
BookDesigner:MaureenForys,HappenstanceType-O-Rama
CoverDesigner:DesignSite
CoverIllustrator:TaniaKac,DesignSite
Copyright©2003SYBEXInc.,1151MarinaVillageParkway,Alameda,
CA94501.
Worldrightsreserved.Theauthorcreatedreusablecodeinthis
publicationexpresslyforreusebyreaders.Sybexgrantsreaderslimited



permissiontoreusethecodefoundinthispublicationorits
accompanyingCD-ROMsolongastheauthorisattributedinany
applicationcontainingthereusablecodeandthecodeitselfisnever
distributed,postedonlinebyelectronictransmission,sold,or
commerciallyexploitedasastand-aloneproduct.Asidefromthisspecific
exceptionconcerningreusablecode,nopartofthispublicationmaybe
storedinaretrievalsystem,transmitted,orreproducedinanyway,
includingbutnotlimitedtophotocopy,photograph,magnetic,orother
record,withouttheprioragreementandwrittenpermissionofthe
publisher.
LibraryofCongressCardNumber:2002116881
ISBN:0-7821-4183-8
SYBEXandtheSYBEXlogoareeitherregisteredtrademarksor
trademarksofSYBEXInc.intheUnitedStatesand/orothercountries.
MasteringandtheMasteringlogoaretrademarksofSYBEXInc.
ScreenreproductionsproducedwithFullShot99.FullShot99©19911999InbitIncorporated.Allrightsreserved.FullShotisatrademarkof
InbitIncorporated.
Internetscreenshot(s)usingMicrosoftInternetExplorer6reprintedby
permissionfromMicrosoftCorporation.
TRADEMARKS:SYBEXhasattemptedthroughoutthisbookto
distinguishproprietarytrademarksfromdescriptivetermsbyfollowingthe
capitalizationstyleusedbythemanufacturer.
Theauthorandpublisherhavemadetheirbesteffortstopreparethis
book,andthecontentisbaseduponfinalreleasesoftwarewhenever
possible.Portionsofthemanuscriptmaybebaseduponpre-release
versionssuppliedbysoftwaremanufacturer(s).Theauthorandthe
publishermakenorepresentationorwarrantiesofanykindwithregardto
thecompletenessoraccuracyofthecontentshereinandacceptno
liabilityofanykindincludingbutnotlimitedtoperformance,

merchantability,fitnessforanyparticularpurpose,oranylossesor
damagesofanykindcausedorallegedtobecauseddirectlyorindirectly


fromthisbook.
Photographsandillustrationsusedinthisbookhavebeendownloaded
frompubliclyaccessiblefilearchivesandareusedinthisbookfornews
reportagepurposesonlytodemonstratethevarietyofgraphicsresources
availableviaelectronicaccess.Textandimagesavailableoverthe
Internetmaybesubjecttocopyrightandotherrightsownedbythird
parties.Onlineavailabilityoftextandimagesdoesnotimplythatthey
maybereusedwithoutthepermissionofrightsholders,althoughthe
CopyrightActdoespermitcertainunauthorizedreuseasfairuseunder
17U.S.C.Section107.
ManufacturedintheUnitedStatesofAmerica
10987654321
SoftwareLicenseAgreement:TermsandConditions
Themediaand/oranyonlinematerialsaccompanyingthisbookthatare
availablenoworinthefuturecontainprogramsand/ortextfiles(the
"Software")tobeusedinconnectionwiththebook.SYBEXhereby
grantstoyoualicensetousetheSoftware,subjecttothetermsthat
follow.Yourpurchase,acceptance,oruseoftheSoftwarewillconstitute
youracceptanceofsuchterms.
TheSoftwarecompilationisthepropertyofSYBEXunlessotherwise
indicatedandisprotectedbycopyrighttoSYBEXorothercopyright
owner(s)asindicatedinthemediafiles(the"Owner(s)").Youarehereby
grantedasingle-userlicensetousetheSoftwareforyourpersonal,
noncommercialuseonly.Youmaynotreproduce,sell,distribute,publish,
circulate,orcommerciallyexploittheSoftware,oranyportionthereof,
withoutthewrittenconsentofSYBEXandthespecificcopyrightowner(s)

ofanycomponentsoftwareincludedonthismedia.
IntheeventthattheSoftwareorcomponentsincludespecificlicense
requirementsorend-useragreements,statementsofcondition,
disclaimers,limitationsorwarranties("End-UserLicense"),thoseEndUserLicensessupersedethetermsandconditionshereinastothat
particularSoftwarecomponent.Yourpurchase,acceptance,oruseofthe


SoftwarewillconstituteyouracceptanceofsuchEnd-UserLicenses.
Bypurchase,use,oracceptanceoftheSoftware,youfurtheragreeto
complywithallexportlawsandregulationsoftheUnitedStatesassuch
lawsandregulationsmayexistfromtimetotime.
REUSABLECODEINTHISBOOK
Theauthor(s)createdreusablecodeinthispublicationexpresslyfor
reusebyreaders.Sybexgrantsreaderslimitedpermissiontoreusethe
codefoundinthispublication,itsaccompanyingCD-ROMoravailablefor
downloadfromourwebsitesolongastheauthor(s)areattributedinany
applicationcontainingthereusablecodeandthecodeitselfisnever
distributed,postedonlinebyelectronictransmission,sold,or
commerciallyexploitedasastand-aloneproduct.
SOFTWARESUPPORT
ComponentsofthesupplementalSoftwareandanyoffersassociated
withthemmaybesupportedbythespecificOwner(s)ofthatmaterial,but
theyarenotsupportedbySYBEX.Informationregardinganyavailable
supportmaybeobtainedfromtheOwner(s)usingtheinformation
providedintheappropriateread.mefilesorlistedelsewhereonthe
media.
Shouldthemanufacturer(s)orotherOwner(s)ceasetooffersupportor
declinetohonoranyoffer,SYBEXbearsnoresponsibility.Thisnotice
concerningsupportfortheSoftwareisprovidedforyourinformationonly.
SYBEXisnottheagentorprincipaloftheOwner(s),andSYBEXisinno

wayresponsibleforprovidinganysupportfortheSoftware,norisitliable
orresponsibleforanysupportprovided,ornotprovided,bytheOwner(s).
WARRANTY
SYBEXwarrantstheenclosedmediatobefreeofphysicaldefectsfora
periodofninety(90)daysafterpurchase.TheSoftwareisnotavailable
fromSYBEXinanyotherformormediathanthatenclosedhereinor
postedtowww.sybex.com.Ifyoudiscoveradefectinthemediaduring
thiswarrantyperiod,youmayobtainareplacementofidenticalformatat


nochargebysendingthedefectivemedia,postageprepaid,withproofof
purchaseto:
SYBEXInc.
ProductSupportDepartment
1151MarinaVillageParkway
Alameda,CA94501
Web:
Afterthe90-dayperiod,youcanobtainreplacementmediaofidentical
formatbysendingusthedefectivedisk,proofofpurchase,andacheck
ormoneyorderfor$10,payabletoSYBEX.
DISCLAIMER
SYBEXmakesnowarrantyorrepresentation,eitherexpressedor
implied,withrespecttotheSoftwareoritscontents,quality,performance,
merchantability,orfitnessforaparticularpurpose.Innoeventwill
SYBEX,itsdistributors,ordealersbeliabletoyouoranyotherpartyfor
direct,indirect,special,incidental,consequential,orotherdamages
arisingoutoftheuseoforinabilitytousetheSoftwareoritscontents
evenifadvisedofthepossibilityofsuchdamage.Intheeventthatthe
Softwareincludesanonlineupdatefeature,SYBEXfurtherdisclaimsany
obligationtoprovidethisfeatureforanyspecificdurationotherthanthe

initialposting.
Theexclusionofimpliedwarrantiesisnotpermittedbysomestates.
Therefore,theaboveexclusionmaynotapplytoyou.Thiswarranty
providesyouwithspecificlegalrights;theremaybeotherrightsthatyou
mayhavethatvaryfromstatetostate.Thepricingofthebookwiththe
SoftwarebySYBEXreflectstheallocationofriskandlimitationson
liabilitycontainedinthisagreementofTermsandConditions.
SHAREWAREDISTRIBUTION
ThisSoftwaremaycontainvariousprogramsthataredistributedas
shareware.Copyrightlawsapplytobothsharewareandordinary
commercialsoftware,andthecopyrightOwner(s)retainsallrights.Ifyou
tryasharewareprogramandcontinueusingit,youareexpectedto


registerit.Individualprogramsdifferondetailsoftrialperiods,
registration,andpayment.Pleaseobservetherequirementsstatedin
appropriatefiles.
COPYPROTECTION
TheSoftwareinwholeorinpartmayormaynotbecopy-protectedor
encrypted.However,inallcases,resellingorredistributingthesefiles
withoutauthorizationisexpresslyforbiddenexceptasspecifically
providedforbytheOwner(s)therein.
ThisbookisdedicatedtomylatemotherPatriciaAnnePriceandtomy
family.You'restillinmyheart,eventhoughyouarefaraway.
Acknowledgments
Manythankstoallthegreat,hard-workingpeopleatSybex-includingTom
Cirtin,DeniseSantoroLincoln,LauraRyan,andEricaYee.


Introduction

WelcometoMasteringC#.NETDatabaseProgramming!Asyoumight
alreadyknow,.NETispoisedtobecomethehotplatformforthenext
waveoftechnologydeployment..NET'sstrengthisthatitisbuiltfromthe
grounduptobeusedinadistributedenvironment-inotherwords,an
environmentthatconsistsofcomputersanddevicesconnectedviaa
network.
Note ThefocusofthisbookishowyouwriteC#programsthat
interactwithadatabase.C#usesADO.NETtointeractwitha
database;ADO.NETisthesuccessortoADO.Inthisbook,
you'lllearnthedetailsofinteractingwithaSQLServer
database.SQLServerisMicrosoft'spremierdatabase
software.
Microsofthaspledgeditscommitmentandresourcestomaking.NETa
pervasivecomponentoflifeinourtechnologicalsociety-ignore.NETat
yourownperil.Thebottomlineisyouneedtolearn.NETifyouwantto
remaincompetitiveintoday's-andtomorrow's-marketplace.
Inanutshell,.NETisacompletelynewframeworkforwritingmanytypes
ofapplications.Theapplicationsyoucanwriteusing.NETinclude
WindowsapplicationsandWeb-basedapplications.Youcanuse.NETto
developsystemscomposedofinterconnectedservicesthatcommunicate
witheachotherovertheInternet.
Inaddition,youcanuse.NETtocreateapplicationsthatrunondevices
suchashandheldcomputersandcellularphones.Althoughother
languagesallowyoutodevelopsuchapplications,.NETwasdesigned
withtheinterconnectednetworkinmind.
The.NETFrameworkconsistsofthreeprimarycomponents:
DevelopmentLanguagesandToolsThedevelopment
languagesthatenableyoutowrite.NETprogramsincludeC#,
VisualBasic.NET(VB.NET),andManagedC++.Microsoftalso
hasaRapidApplicationDevelopment(RAD)toolcalledVisual



Studio.NET(VS.NET)thatallowsyoutodevelopprogramsinan
integrateddevelopmentenvironment(IDE).You'lluseC#andVS
.NETinthisbook.
CommonLanguageRuntime(CLR)CLRmanagesyour
runningcodeandprovidesservicessuchasmemory
management,threadmanagement(whichallowsyoutoperform
multipletasksinparallel),andremoting(whichallowsobjectsin
oneapplicationtocommunicatewithobjectsinanother
application).TheCLRalsoenforcesstrictsafetyandaccuracyof
yourexecutablecodetoensurethatnotamperingoccurs.
FrameworkBaseClassLibraryTheFrameworkBaseClass
LibraryisanextensivecollectionofcodewrittenbyMicrosoftthat
youcanuseinyourownprograms.Forexample,amongmany
otherfunctions,theFrameworkBaseClassLibrarycontainscode
thatallowsyoutodevelopWindowsapplications,access
directoriesandfilesondisk,interactwithdatabases,andsend
andreceivedataacrossanetwork.


WhoShouldReadThisBook?
ThisbookwaswrittenforprogrammerswhoalreadyknowC#.Itcontains
everythingyouneedtoknowtomasterdatabaseprogrammingwithC#.
Nopriorexperienceofdatabasesisassumed,butifyoualreadyhave
someknowledgeofdatabasesoftwaresuchasSQLServerorOracle,
you'llbeofftoarunningstart.
Note Ifyoudon'tknowC#,IrecommendthebookMasteringVisual
C#.NETfromSybex(2002).



HowtoUseThisBook
Thisbookisdividedintothreeparts.InPart1,"IntroductiontoADO.NET
andDatabases,"you'lllearneverythingyouneedtoknowabout
databases.You'llalsobeintroducedtoADO.NET,whichenablesyourC#
programstointeractwithadatabase.InPart2,"FundamentalDatabase
ProgrammingwithADO.NET,"you'lllearntheC#programmingwith
ADO.NETfromthegroundup.InPart3,"AdvancedDatabase
ProgrammingwithADO.NET,"you'llgobeyondthebasicstolearn
programmingtechniquesneededbyprofessionaldatabasedevelopers.
Thefollowingsectionsdescribethechaptersindetail.

Part1:"IntroductiontoADO.NETandDatabases"
InChapter1,"IntroductiontoDatabaseProgrammingwithADO.NET,"
you'llseehowtouseADO.NETinaC#programtointeractwitha
database.YoualsolearnaboutMicrosoft'sRADtool,VisualStudio.NET.
Finally,you'llseehowtousetheextensivedocumentationfromMicrosoft
thatcomeswith.NETandSQLServer.
InChapter2,"IntroductiontoDatabases,"you'lllearnthedetailsofwhat
databasesareandhowtheyareusedtostoreinformation.You'llseethe
useofaSQLServerdatabasenamedNorthwind.Thisdatabasecontains
theinformationforthefictitiousNorthwindCompany,whichsellsfood
products.Thisdatabaseisoneoftheexampledatabasesthatistypically
installedwithSQLServer.
InChapter3,"IntroductiontotheStructuredQueryLanguage,"you'll
learnhowtousetheStructuredQueryLanguage(SQL)toaccessa
database.You'llseehowyouuseSQLtointeractwiththeNorthwind
database,andhowtoretrieveandmodifyinformationstoredinthat
database.
InChapter4,"IntroductiontoTransact-SQLProgramming,"you'llbe

introducedtoprogrammingwithMicrosoft'sTransact-SQL.Transact-SQL
enablesyoutowriteprogramsthatcontainSQLstatements,alongwith
standardprogrammingconstructssuchasvariables,conditionallogic,


loops,procedures,andfunctions.
InChapter5,"OverviewoftheADO.NETClasses,"you'llgetanoverview
oftheADO.NETclasses.You'llalsoseeaC#programthatconnectstoa
database,storestherowslocally,disconnectsfromthedatabase,and
thenreadsthecontentsofthoselocalrowswhiledisconnectedfromthe
database.Thisabilitytostorealocalcopyofrowsretrievedfromthe
databaseisoneofthemainstrengthsofADO.NET.
InChapter6,"IntroducingWindowsApplicationsandADO.NET,"you'llbe
introducedtoWindowsapplications.AWindowsapplicationtakes
advantageofdisplayingandusingthemouseandkeyboardforinput.
Windowsprovidesgraphicalitemssuchasmenus,textboxes,andradio
buttonssoyoucanbuildavisualinterfacethatwillbeeasytouse.You'll
seehowtobuildWindowsapplicationsthatinteractwiththeNorthwind
database.

Part2:"FundamentalDatabaseProgrammingwith
ADO.NET"
InChapter7,"ConnectingtoaDatabase,"you'lllearnthedetailson
connectingtoadatabase.TherearethreeConnectionclasses:
SqlConnection,OleDbConnection,andOdbcConnection.Youuse
anobjectoftheSqlConnectionclasstoconnecttoaSQLServer
database.YouuseanobjectoftheOleDbConnectionclasstoconnect
toanydatabasethatsupportsOLEDB(ObjectLinkingandEmbedding
forDatabases),suchasOracleorAccess.Youuseanobjectofthe
OdbcConnectionclasstoconnecttoanydatabasethatsupportsODBC

(OpenDatabaseConnectivity).Ultimately,allcommunicationwitha
databaseisdonethroughaConnectionobject.
InChapter8,"ExecutingDatabaseCommands,"you'lllearnthedetails
onexecutingdatabasecommands.YouuseaCommandobjecttoexecute
aSQLSELECT,INSERT,UPDATE,orDELETEstatement.Youcanalso
useaCommandobjecttocallastoredprocedure,orretrievealltherows
andcolumnsfromaspecifictable.


InChapter9,"UsingDataReaderObjectstoReadResults,"you'llsee
howtouseaDataReaderobjecttoreadresultsreturnedfromthe
database.YouuseaDataReaderobjecttoreadrowsretrievedfromthe
databaseusingaCommandobject.
InChapter10,"UsingDataSetObjectstoStoreData,"you'lllearnhow
touseaDataSetobjecttostoreresultsreturnedfromthedatabase.
DataSetobjectsallowyoutostoreacopyofthetablesandrowsfrom
thedatabase,andyoucanworkwiththatlocalcopywhiledisconnected
fromthedatabase.
InChapter11,"UsingDataSetObjectstoModifyData,"you'llexamine
howtomodifytherowsinaDataSetandthenpushthosechangesto
thedatabaseviaaDataAdapter.
InChapter12,"NavigatingandModifyingRelatedData,"you'lldelveinto
thedetailsofhowyounavigaterelateddataintables,makechangesin
thatdatainmemory,andfinallypushthosechangestothedatabase.
InChapter13,"UsingDataViewObjects,"you'llseehowtouse
DataViewobjectstofilterandsortrows.TheadvantageofaDataView
isthatyoucanbindittoavisualcomponentinaWindowsorASP.NET
application.

Part3:"AdvancedDatabaseProgrammingwithADO.NET"

InChapter14,"AdvancedTransactionControl,"you'lldelveinto
advancedtransactioncontrolusingSQLServerandADO.NET.
InChapter15,"IntroducingWebApplications:ASP.NET,"you'lllearnthe
basicsofASP.NET,andyou'llseehowtouseVisualStudio.NETto
createASP.NETapplications.
InChapter16,"UsingSQLServer'sXMLSupport,"you'lllearnaboutSQL
Server'sextensivesupportforXML.You'llalsoseehowtostoreXMLina
C#programusingXmlDocumentandXmlDataDocumentobjects.
InChapter17,"WebServices,"you'lllearnhowtobuildasimpleweb


service,whichisasoftwarecomponentthatmaybeusedacrossthe
Web.Forexample,youcouldbuildaebservicethatallowsonecompany
tosendanothercompanyanorderacrosstheWebusingXML.


DownloadingtheExamplePrograms
Throughoutthisbook,you'llseemanyexampleprogramsthatillustrate
theconceptsdescribedinthetext.Thesearemarkedwithalisting
numberandtitle,suchastheoneshownhere:
LISTING1.1:FIRSTEXAMPLE.CS
Thefilenameswillcorrespondtothelistingname:FirstExample.csis
thefilenameforListing1.1.YoucandownloadaZipfilecontainingthe
programsfromtheSybexWebsiteatwww.sybex.com.Youcanusea
programsuchasWinZiptoextractthecontentsoftheZipfile.
Whenyouunzipthisfile,onedirectoryforeachchapterwillbecreated.
Eachdirectorywillcontainthefollowingsub-directoriesasrequired:
programsContainstheC#programs.
sqlContainsSQLscripts.
VS.NETprojectsContainstheVisualStudio.NETprojects.

xmlContainstheXMLfiles.
Note Notallchaptersreferenceprograms,sqlscripts,etc.,and
thereforemaynotcontainalltheprevioussub-directories.


Part1:IntroductiontoADO.NETandDatabases


ChapterList
Chapter1:IntroductiontoDatabaseProgrammingwithADO.NET
Chapter2:IntroductiontoDatabases
Chapter3:IntroductiontoStructuredQueryLanguage(SQL)
Chapter4:IntroductiontoTransact-SQLProgramming
Chapter5:OverviewoftheADO.NETClasses
Chapter6:IntroducingWindowsApplicationsandADO.NET


Chapter1:IntroductiontoDatabase
ProgrammingwithADO.NET


Overview
ADatabaseisanorganizedcollectionofinformationthatisdividedinto
tables.Eachtableisfurtherdividedintorowsandcolumns;these
columnsstoretheactualinformation.Youaccessadatabaseusing
StructuredQueryLanguage(SQL),whichisastandardlanguage
supportedbymostdatabasesoftwareincludingSQLServer,Access,and
Oracle.
Inthischapter,you'llseeaC#programthatconnectstoaSQLServer
database,retrievesanddisplaysthecontentsstoredinthecolumnsofa

rowfromatable,andthendisconnectsfromthedatabase.You'llalsosee
programsthatconnecttoAccessandOracledatabases.
You'llalsolearnaboutMicrosoft'srapidapplicationdevelopment(RAD)
tool,VisualStudio.NET(VS.NET).VS.NETenablesyoutodevelop,
run,anddebugprogramsinanintegrateddevelopmentenvironment.
ThisenvironmentusesallthegreatfeaturesofWindows,suchasthe
mouseandintuitivemenus,andincreasesyourproductivityasa
programmer.
Inthefinalsectionsofthischapter,you'llseehowtousetheextensive
Microsoftdocumentationthatcomeswiththe.NETSoftware
DevelopmentKit(SDK)andVS.NET.You'llfindthisdocumentation
invaluableasyoubecomeanexpertwithADO.NETandC#.You'llalso
learnhowtousetheSQLServerdocumentation.
Featuredinthischapter:
Obtainingtherequiredsoftware
DevelopingyourfirstADO.NETprogram
ConnectingtoAccessandOracledatabases
IntroducingVisualStudio.NET
Usingthe.NETdocumentation


UsingtheSQLServerdocumentation


ObtainingtheRequiredSoftware
BeforeyoucandevelopC#programs,you'llneedtoinstalleitherthe
.NETSoftwareDevelopmentKit(SDK)orVS.NET.Youcandownload
the.NETSDKat(search
fortheMicrosoft.NETFrameworkSoftwareDevelopmentKit).Youcan
purchaseatrialorfullcopyofVS.NETfromMicrosoftat

/>Toinstallthe.NETSDK,runtheexecutablefileyoudownloadedand
followtheinstructionsonthescreentoinstallitonyourcomputer.To
installVS.NET,runthesetup.exefileonthediskandfollowthe
instructionsonthescreen.
You'llalsoneedacopyoftheSQLServerdatabasesoftware.Attimeof
writing,youcandownloadatrialversionofSQLServerfromMicrosoftat
Youcanalsopurchaseatrialor
fullcopyofSQLServerfromMicrosoft'sWebsite.
ThisbookusestheDeveloperEditionoftheSQLServer2000software
andusesadatabasenamedNorthwind.Thisdatabasecontainsthe
informationforthefictitiousNorthwindCompany,whichsellsfood
productstocustomers.Northwindisoneoftheexampledatabasesthat
youcaninstallwithSQLServer.CustomerinformationintheNorthwind
databaseisstoredinatablenamedCustomers;you'llseetheuseof
thistableintheexampleprogramlaterinthischapter.
Ifyoudon'twanttodownloadorpurchaseatrialversionofSQLServer,
the.NETSDK(andVS.NET)comeswithastand-alonedesktop
databaseserverknownastheMicrosoftSQLServer2000Desktop
Engine(MSDE2000).MSDE2000hasaversionoftheNorthwind
databasethatyoucanuseinsteadoftheSQLServerNorthwind
database-althoughyouwon'tgetallofthegraphicaladministrationtools
thatcomewithSQLServer.Ifyou'reusingthe.NETSDKandwantto
installMSDE2000,selectStart➣Microsoft.NETFrameworkSDK➣
SamplesandQuickStartTutorials.Ifyou'reusingVS.NETandwantto
installMSDE2000,runthesetup.exeprogramthatyouusetoinstallVS


.NETandselectMSDE2000asanewfeaturetoinstall.
Note YoucanlearnmoreaboutMSDE2000at
/>


×