ContentsOverview1OverviewofADO.NET2ConnectingtoaDataSource10AccessingDatawithDataSets12UsingStoredProcedures28Lab3:UsingADO.NETtoAccessData37AccessingDatawithDataReaders46BindingtoXMLData53Review59Module3:UsingADO.NETtoAccessDataInformationinthisdocumentissubjecttochangewithoutnotice.Thenamesofcompanies,products,people,characters,and/ordatamentionedhereinarefictitiousandareinnowayintendedtorepresentanyrealindividual,company,product,orevent,unlessotherwisenoted.Complyingwithallapplicablecopyrightlawsistheresponsibilityoftheuser.Nopartofthisdocumentmaybereproducedortransmittedinanyformorbyanymeans,electronicormechanical,foranypurpose,withouttheexpresswrittenpermissionofMicrosoftCorporation.If,however,youronlymeansofaccessiselectronic,permissiontoprintonecopyisherebygranted.Microsoftmayhavepatents,patentapplications,trademarks,copyrights,orotherintellectualpropertyrightscoveringsubjectmatterinthisdocument.ExceptasexpresslyprovidedinanywrittenlicenseagreementfromMicrosoft,thefurnishingofthisdocumentdoesnotgiveyouanylicensetothesepatents,trademarks,copyrights,orotherintellectualproperty.2001MicrosoftCorporation.Allrightsreserved.Microsoft,ActiveX,FrontPage,JScript,MS-DOS,MSDN,Outlook,PowerPoint,VisualBasic,VisualC#,VisualInterDev,VisualStudio,Windows,WindowsMediaPlayer,andWindowsNTareeitherregisteredtrademarksortrademarksofMicrosoftCorporationintheU.S.A.and/orothercountries.Otherproductandcompanynamesmentionedhereinmaybethetrademarksoftheirrespectiveowners.Module3:UsingADO.NETtoAccessData1OverviewOverviewOverviewofADO.NETConnectingtoaDataSourceAccessingDatawithDataSetsUsingStoredProceduresAccessingDatawithDataReadersBindingtoXMLDataOneofthereasonsforthewidespreaduseofMicrosoft®ActiveServerPages(ASP)isthatitfacilitatesaccesstodatastores.ASP.NETexpandsonthiscapabilitywiththeintroductionofADO.NET,whichoffersarichsuiteofdatahandlinganddatabindingfunctionsformanipulatingalltypesofdata.Aftercompletingthismodule,youwillbeableto:DescribetheADO.NETobjectmodel.ConnecttoadatasourcebyusingADO.NET.RetrievedatafromadatabasebyusingDataReaders,andDataSets.Displaythedatafromadatabaseontheclientbyusinglist-boundcontrols.CustomizethelookofRepeatercontrolswithtemplates.UsestoredprocedurestoreturnRecordsets.ReaddatafromanExtendedMarkupLanguage(XML)fileintoDataSets.TherearemanychangesbetweentheBeta1andBeta2versionsofASP.NETwithrespecttodatabinding.Foradetailedlistofchanges,seeAppendixA,inCourse2063A,IntroductiontoASP.NET.Note2Module3:UsingADO.NETtoAccessDataOverviewofADO.NETOverviewofADO.NETTheADO.NETObjectModelAnimation:UsingADO.NETtoAccessDataRecordSetsvs.DataSetsUsingNamespacesADO.NETisnotarevisionofMicrosoftActiveX®DataObjects(ADO),butanewwaytomanipulatedatathatisbasedondisconnecteddataandXML.AlthoughADOisanimportantdataaccesstoolwithinASP,itdoesnotprovideallthenecessaryfeaturesfordevelopingrobustandscalableWebapplications.InspiteofADO'srichobjectmodelandrelativeeaseofuse,itisconnectedbydefault,reliesonanOLEDBprovidertoaccessdata,anditisentirelyComponentObjectModel(COM)-based.ADO.NEThasbeendesignedtoworkwithdisconnecteddatasets.Disconnecteddatasetsreducenetworktraffic.ADO.NETutilizesXMLastheuniversaltransmissionformat.ThisguaranteesinteroperabilityaslongasthereceivingcomponentrunsonaplatformwhereanXMLparserisavailable.WhenthetransmissionoccursthroughXML,itisnolongernecessarythatthereceiverbeaCOMobject.Thereceivingcomponenthasnoarchitecturalrestrictionswhatsoever.AnysoftwarecomponentcanshareADO.NETdata,aslongasitusesthesameXMLschemafortheformatofthetransmitteddata.Inthissection,youwilllearnaboutADO.NET.YouwilllearnaboutthenewandmodifiedobjectsinADO.NET.YouwillalsolearnaboutsomeofthenewnamespacesthatareincludedinASP.NET.Module3:UsingADO.NETtoAccessData3TheADO.NETObjectModelADO.NETevolvedfromtheADOdataaccessmodel.ByusingADO.NET,youcandevelopapplicationsthatarerobustandscalable,andthatcanuseXML.ADO.NEThassomeofthesameobjectsasADO(liketheConnectionandCommandobjects),andintroducesnewobjects,suchasDataSets,DataReaders,andDatasetCommands.SomeofobjectsinADO.NETrepresentupdatesofexistingobjects(suchasConnectionandCommand),whileothersarecompletelynew(suchasDataReader,DataSet,DataView,andDataSetCommand.ConnectionObjectsConnectionobjectsareusedtotalktodatabases.Theyhaveproperties,suchasDataSource,UserID,andPassword,thatareneededtoaccessaparticularDataSource.Commandstraveloverconnections,andresultsetsarereturnedintheformofstreamsthatcanbereadbyDataReadersorpushedintoDataSetobjects.TherearetwokindsofconnectionobjectsinADO.NET:SQLConnectionandADOConnection.CommandObjectsCommandobjectscontaintheinformationthatissubmittedtoadatabase.Acommandcanbeastoredprocedurecall,anupdatestatement,orastatementthatreturnsresults.Youcanalsouseinputandoutputparametersandreturnvalues.InADO.NET,youcanusetwokindsofcommandobjects:SQLCommandandADOCommand.4Module3:UsingADO.NETtoAccessDataDataReaderObjectsADataReaderisaread-only/forward-onlyviewonthedata.Itprovidesasimpleandlightweightwayoftraversingthroughrecordsets.Forexample,ifyouwantedtosimplysho