外文翻译--Designing a Database Application in VB 6.doc
DesigningaDatabaseApplicationinVB6.0AbstractBeforeyoustarttodesignadatabase,itsimportantyouunderstandexactlywhatadatabaseisandwhattypesofdatabasesyouhavetochoosefrom.Theapplicationtypewillaffectthedatabasetypethatyouchoose.WhatIsaDatabase?Adatabaseisreallyasystemthatcontainsmanydifferentobjectsusedtogethertoallowyourapplicationfastandefficientaccesstothedata.Youcanusemanyexamplesofdatabaseswithyourapplication.Themostcommonoftheseareasfollows:·MicrosoftAccess;·MicrosoftFoxPro;·OraclePersonalEdition7ior8i;and·MSSQLServer7.00isonlyafewtomention.Allthesedatabasescanrunonastandalonecomputerandallowyoutocreateverycomplexdatabasesforyourapplications.Pickingtherightdatabaseforyourapplicationisextremelyimportant,becausethewrongonewillaffectperformanceandmakeyourjobasadevelopersomuchmoredifficult.Beforestartingthedesignprocess,youneedtoselectadatabase.WhenworkingwithVisualBasic,thedatabasethatyoucanchoosefromfallintotwodistinctgroups:LocalDatabasescanbeaccesseddirectlyfromVisualBasicthroughVisualBasicsdatabaseJetengine;andRemotedatabasescannotbeaccessedbyusingVisualBasicsstandarddatabaseaccesscapabilities.Understandingthedifferenceswillhelpyouselectthecorrectdatabaseforyourapplication.However,inVisualBasic6,thereisnowawaytoaccessbothlocalandremotedatabasesusingthesamedatabaseaccesscontrolsandobjectsknownastheActiveXDataObjects.UnderstandingUniversalDataAccess(UDA)Asdatabaseshavegrownandmovedoffthelocalcomputerandontonetworkeddatabaseservers,themethodsemployedtoaccessthedatabaseshavechanged.Microsofthasaddressedthesechangesbydevelopingstrategytoallowforanycompanyordatabasetobeaccessedthesameway.ThisiscalledUniversalDataAccess,orUDA.UnderstandingwhatUDAmeansisnotassimpleasunderstandingtouseit.ThereasonforthisisthatUDAisasetofrulesandaccessmethodsthatmustbefollowedbyanycompanythatiscreatingadatabaseaccessmethodtobeused.Thisallowsyou,theprogrammer,toaccessanydatabasethesamewayButwhatisUDA?UniversalDataAccessisaplatform,applicationsandtoolsconceptthatMicrosofthasdevelopedthatdefinesanddeliversthestandardsforallfutureapplicationdevelopment.UsingUDAstandardswillprovidehighperformanceaccesstomanytypesofdataandinformationthatresideonmultipleplatforms,andaprogramminginterfacethatwillworkwithalmostanytoolorlanguageusingtheskillsthatdevelopersalreadyhave.ThisisaccomplishedbyusingMicrosoftsDataAccessComponents(MDAC),aswellasanintegratedsetoftechnologies,whichincludeActiveXDataComponents(ADO),OLEDB,andOpenDatabaseConnectivity(ODBC).Thebenefitsofusingthesestandardsincludethefollowing:HighperformanceaccesstodataProvidestheabilitytoscaleanyapplicationorcomponenttosupportconcurrentlyconnecteduserswithoutlosingperformance;ReliabilityReducesthenumberofcomponentstosupportontheclientPC;andWideindustrysupportManyvendorsincludingMicrosofthavealreadyannouncedsupportfortheUDAstandards.InpreviousreleasesofVisualBasic,youneededtochoosefromeitherDAO(local)accessmethodstodataorRDO(remote)accesstodata.Now,withthesupportofUDA,VisualBasichasathirdmethodfordataaccesscalledADO,orActiveXDataObjects.Thisallowsyoutocombinethedifferentwaysofaccessingdataintoonesetofprogrammingcallsandobjects.ADOworksinconjunctionwithOLEDBandODBCtoprovideaccesstoonedatabaseyoumightbeworkingwith.Gettingforward,MicrosoftplanstophaseoutODBCinfavourofOLEDBandtheUDAstandards.However,forthenearfuture,DAOandRDO,aswellasODBC,willstillbesupportedtoallowdeveloperstoslowlymoveuptothenewstandardsofdataaccess.LocalDatabasesLocaldatabasesaregenerallymuchsmallerthantheremotetypeofdatabase.Thefollowingdatabasesfallintothiscategory:·MicrosoftAccess;·MicrosoftFoxPro;·LotusWorksheets;·MicrosoftExcelWorksheets;·dBase;·Paradox;and·ASCII.Asyoucansee,thesePC-residentdatabasetypeshavebeenaroundforawhileandareavailablefromalmostanycomputersoftwarestore.AccessingthesedatabasesdoesntrequireanyothersoftwaretobeinstalledonthePC,nordoesitrequirespecialknowledgeonhowtoworkwiththem.However,thesizeoflocaldatabasesisrestricted.MicrosoftAccess97databasescantexceed1GB(gigabyte).Localdatabasesaregenerallyusedforsingle-userapplicationssuchascheckbooks,addressbooks,andpersonalinformationmanagers.Someenterprisingteenagershavecreateddatabaseapplicationsthathelpthemkeeptrackofbaseballcardsorvideotapes.Soindecidingwhatyourapplicationwilladdressandhowitwillbeusedactuallyhelpsyouinthedatabaseselectionprocess.RemoteDatabasesBydefinitionremotedatabasesdontresideontheusersPC,butthisisnotalwaystrue.Infact,aremotedatabaseisanytypeofdatabasethatrequiresanODBC(OpenDatabaseConnectivity)driverforanapplicationtoaccessit.ODBCdatabasesfallintotwomaincategories:onethatrunonasinglePCandthelargercorporateonesthatrequirelarge,verypowerfulcomputers(calledservers)withlargeamountsofavailablediskspace.DatabaseserversareusedtoseparatetheworkloadbetweentheclientPC(wheretheapplicationexecutes)andthedatabasesystem(wherethedatabasequeriesareperformed).ThisprovidestheapplicationwithfastdataaccesswithoutslowingdowntheusersPC.Mostthelargeserver-typedatabasesprovideversionsthatwillrunonstandalonePCs.Mostlargecorporationsuseoneofthefollowingdatabasesystems(thoughthisisnottosaythatothersarentoutthere):·Oracle;·Sybase;and·MicrosoftSQLServer.UsingaremotedatabaserequiresyoutouseeithertheremotedatabaseobjectsavailableonlyintheEnterpriseversionofVisualBasic6orthenewActiveXDataObjectsavailableinallreleasesofVisualBasic6.Ifyouredesigninganapplicationthatwilluseoneoftheselargedatabases,however,thebestwaytocreatetheapplicationthatwillusethesingle-PCversionduringthedesign,developmentandtestingprocess.Then,wewhentheapplicationiscompleted,switchtoODBCconnectiontothelarger,server-basedversion.BuildingtheInitialDesignCreatinganapplicationisalotlikebuildingahouse.Forawell-builthouse,youneedablueprinttofollow,buttocreateagoodblueprint,youneedtoknowwhosgoingtoliveinthehouseandwhattheirlivingstyleswillbe.Thiswillhelpyoudecidethenumberandsizesofthebedrooms,whatcolourstouse,andsoon.Withanapplication,theblueprintisthetechnicalspecifications;thefunctionalspecificationsarewhatyouneedtoknowtocreatethetechnicalspecifications.Now,manybooksteachtheoverallapplicationdesignprocessbyusingverysimplisticexampleapplications.Thedescriptionoftheapplicationwemustdevelopisasfollows:PersonalAddress/PhoneBookThisapplicationwillkeeptrackofnames,addresses,andphonenumbersbyname.Itwillallowasmanydifferentaddressesandphonenumbersasneeded.Also,itwillallowtheentryofsomepersonalinformation(suchasbirthdate,spousesname,andchildrennames)tobedeterminedlater.Itwillalsoprovidereportsinseveralformatsandallowuserstosearchthedatabaseforaparticularperson.ChoosingtheTasksDefiningtasksfortheapplicationalsodefinesitscomplexity.Forexample,thisapplicationisanaddress/phonebook,ifyoudecidetogiveuserstheabilitytoselectaphonenumberandhavethecomputerdialitforthem.Toaddthisfunctionalitytotheapplication,youneedtoknowhowtotestfortheexistenceofthemodem,connecttothatmodem,andthenactuallydialthatnumber.Ifyoudontknowhowtoaddthisfunctionality,youmightconsiderwaitingtoadditaftertheinitialversionoftheapplicationiscreatedandtested.Thisiswhatreleasingnewversionsareallabout.Keeptheinitialversionofthisapplicationatasimplerlevel.Thebestwaytodesignanapplicationistosaytoyourself,“WhatwouldIwanttheapplicationtodoifIweretheuser?”Basically,yourethefirstandmostimportantuseroftheapplication.Thisapproachmightnotworkforthelarger,corporate-typeapplication,butitdoesworkforthesmaller,morepersonaltypes.Evenbeforeyoulistthedifferenttasksthattheapplicationwillperform,youneedtodecidewhattypeofapplicationinterfacetouseforthisapplication.Forthissampleapplication,usetheExplorer-styleinterface.Toreviewthisstyle,theinitialformthatusersseeandremaininformostoftheapplicationwillresembletheoneshowninFigure1.Figure1-Thisinterfaceincludesmanyofthecontrolsthatyouhavelearnedearlier.Okay,wehavepickedtheapplicationthatyoullcreatenowyouneedtolistthemainfunctionsthatitwillperform.Thinkofwhattheapplicationisforandthenlistwhatyouwantittodo.Fromthisreasoning,youshouldgetthefollowinglist:·Keepnamesandaddresses;·Searchforaparticularname;·Printdifferenttypesofreports;·Allowfordifferentusers;and·Enableeasymaintenanceoftheapplication.Now,ifthislistseemssimplistic,itis!Youwouldthenexpandeachiteminthislistuntilyouresatisfiedwiththeresult.Letsexpandeachoftheprecedingtasksandaddamoredetailtothedefinition.KeepingNamesandAddressesWhatdoyoureallymeanwhenyousay“Keepnamesandaddresses?”Itusuallymeansthatyouwanttokeeptrackofthestandardinformationfoundinanystandardtelephonebookyoulookat.Thefirststepindefiningallthemini-tasksrequiredforthistopicistolistthedataelementsyouwanttoputinthedatabase.Table1liststhedataelementsthatyoucanuseforthistypeofapplication.NameTypeFirstNameStringLastNameStringSpouseNameStringChildNameStringAddressStringCityStringStateStringZIPIntegerE-MailAddressStringPhoneLongBirthDateDateNotesStringTable1:DataElementsThatCanBeIncludedInTheApplicationDatabase.