Data layer

honggarae 22/01/2022 910

Overview

Thedatalevel(datalevel)referstooneoftheASP.NETthree-tiersystems,includingthedatalayer,businesslogiclayerandpresentationlayer.

WhenusingASP.NETtechnologytodeveloplargeandmedium-sizedapplications,athree-tierdevelopmentmodelisoftenused.Amongthem,theoperationsonthedatabaseareencapsulatedinthedatalayer,andthelogicaloperationsonthedataareencapsulatedinthebusinesslogiclayer.Theabovetwolayersareintheformof.NETclasslibraries,andthepresentationlayerisWebformpagesandusercontrols.

TheapplicationprogramisestablishedthroughtheASP.NETthree-tiersystemstructuretorealizethefunctionofqueryingandaddingrecordstotheChengjidatabase.

Firstcreateafolder3TiersSampleontheharddisk,andcreateasubfolder3TiersSample_Webinthefolder,andthencreatethesubfolderasavirtualdirectory.Thewaytocreateitis:right-clickthefolder,selectthe[Properties]iteminthepop-upmenu,thenselectthe[WebSharing]tabtosharethefolder,andclickthe[OK]button.Next,createablanksolutionthroughVisualStudio.NET2003,browsethedirectory,andlocatethesolutiontothefolder3TiersSample.Next,createthedatalayer,businesslogiclayer,andpresentationlayer.

Datalayercreation

Inthesolutionexplorer,right-clickthesolutionandselect[Add]item,select[NewProject]inthesubmenu,andlocatethefolderIn3TiersSample,createaC#classlibraryprojectandnameit3TiersSample_Data.

AddtheclassfileChengji.cstothedatalayer,andcompletethemethodsGetAllandInsertCJ.Amongthem,theGetAllmethodisusedtoreturnallthedatainthedatatableintheformofadataset,andthereturneddatasetwillbecalledbythebusinesslogiclayer;theInsertCJmethodisusedtoaddnewdatarecordstothedatatable,andthedatainallfieldsisdeterminedbythebusinessThelogiclayerispassedtothedatalayer.

Then,right-clicktheprojectnameintheSolutionExplorer,andselect[Generate]inthepop-upmenutogeneratethedatalayerclasslibrary.Thisclasslibraryexistsinthe3TiersSample_Data\bin\Debugdirectoryintheformofadynamiclinklibraryandisnamed3TiersSample_Data.dll.

Datalayerdesign

Thedatalayeriscomposedofclasslibraryfiles,responsibleforadding,deleting,modifyingandqueryingdatainthedatabase,andpassingthedatatotheupperbusinessThelogicallayerhandlesit.TherearefivecategoriesintheMyNewsdatalayer.

Amongthem,theconnectionstringisreadfromtheWeb.configfile.Thedatalayerisonlyresponsibleforperformingcorrespondingoperationsinthedatabase,anddoesnotcareaboutthesourceoftheparameters,nordoesitcareabouttheoperationstobeperformedonthereaddata.Therefore,onlymethodsaredefinedinthedatalayertoimplementrelatedoperations,andtherequireddataistransmittedthroughthebusinesslogiclayer.

Latest: Public key

Next: Resin Matrix Composite