利用IBM DB2数据库建立ASP NET网站毕业论文外文翻译Word文档格式.docx

上传人:b****5 文档编号:21158671 上传时间:2023-01-28 格式:DOCX 页数:18 大小:397.19KB
下载 相关 举报
利用IBM DB2数据库建立ASP NET网站毕业论文外文翻译Word文档格式.docx_第1页
第1页 / 共18页
利用IBM DB2数据库建立ASP NET网站毕业论文外文翻译Word文档格式.docx_第2页
第2页 / 共18页
利用IBM DB2数据库建立ASP NET网站毕业论文外文翻译Word文档格式.docx_第3页
第3页 / 共18页
利用IBM DB2数据库建立ASP NET网站毕业论文外文翻译Word文档格式.docx_第4页
第4页 / 共18页
利用IBM DB2数据库建立ASP NET网站毕业论文外文翻译Word文档格式.docx_第5页
第5页 / 共18页
点击查看更多>>
下载资源
资源描述

利用IBM DB2数据库建立ASP NET网站毕业论文外文翻译Word文档格式.docx

《利用IBM DB2数据库建立ASP NET网站毕业论文外文翻译Word文档格式.docx》由会员分享,可在线阅读,更多相关《利用IBM DB2数据库建立ASP NET网站毕业论文外文翻译Word文档格式.docx(18页珍藏版)》请在冰豆网上搜索。

利用IBM DB2数据库建立ASP NET网站毕业论文外文翻译Word文档格式.docx

ASP.NETisthenext-generationWebapplicationframeworkbuiltonthe.NETplatform--thesuccessortoMicrosoft'

sActiveServerPages(ASP)framework.ASP.NETallowsrapidapplicationdevelopment(RAD)ofWebapplicationsinasimilarwaytoWindowsFormapplications.CreatingWindows-styleWebapplicationsonthe.NETplatformisalsoknownasWebForms.

TobeginwithWebForms,yourcomponentsneedtobeplacedontoaWebFormand,liketypicalWindowsdevelopment,yousetthepropertiesforthecomponentandwritetheeventhandlersforyourcomponents.Inthisway,developingWebapplicationsisextremelysimple.

AccessingDB2fromBorlandC#Builder--theBorlandDataProviders(BDP)

CreatingdynamicInternetapplicationsiseasyenough,butinmostcasesyouwillwanttodevelopdata-drivenapplicationsconnectingtoyourDB2UDBdatabase.ThisiswheretheBDPcomponentscomein.Figure1showsthebasiccomponentsthatyouneedtoconnecttothedata.AllthecomponentsyouneedtoconnectthroughtoDB2UDBcanbefoundontheBDPandDataComponentspagesoftheToolPalette.

Figure1.SelectingtheBDPcomponents

DB2UDBoffersscalability,robustness,easyconfiguration,and--mypersonalfavorite--theabilitytocreatestoredproceduresinbothSQLandJava,soitisveryeasytoconnecttoitwiththeBDPcomponents.ThemaincomponentsthatyouwillusetoconnecttothedatabasearetheBdpConnectioncomponent,theBdpDataAdaptercomponent,theBdpCommand,andtheDataSetcomponent:

Figure2.TheBDPcomponentsworktogetherforyourdata.

DataSetscontainacollectionoftables,therelationshipsbetweenthetables,andotherinformationsuchastheconstraintsforthedata.EachqueryretrievedbytheBdpDataAdapterisstoredasaDataTable,anditisthisDataTableobjectthatholdsthedatafromthedatabase.Forsimplicity,wewillworkwithasingleDataSetthatcontainsoneDataTable.

TheDataSetcomponent,however,isdesignedtoworkwithoutapermanentconnectiontothedatabase.TheprocessofretrievingdatafromtheBDPcomponentsintotheDataSetistorequestthattheBdpDataAdapterconnecttothedatabase,andthenrequestthattheBdpDataAdapterfillthecontentsoftheDataSetwiththeresultsofoneormorequeries.OnceyourDataSetispopulated,youcandisconnectfromthedatabase.Wheneveryouneedtoretrieveorupdatedatafromthedatabase,yousimplyreconnecttotheBdpDataAdapter.Thatway,ifnetworkconnectivitytoDB2UDBislostyoucanstillworkwithalocalcopyofthedata,inpreparationforwhenaccesstotheserverisavailable.

StartingtobuildyourWebApplication

Let'

sstartondevelopingaWebgriddisplayingtheresultsofasingledatabasequery.First,youwillneedtocreateanewWebApplication.FromtheC#BuilderIDE,selectFile|New|OtherandthenselectanewASP.NETWebApplication.

Afteryouhaveselectedtheoptionsforyourapplication,youhaveaWebFormthatyoucanworkwith.Indesignmode,youcansetupthedisplayasifyouwereeditinganHTMLdocumentinaWYSIWYGeditor(seeFigure3).

ThemagicreallystartshappeningwhenyoustartdroppingtheASP.NETcomponentsontoyourWebform.TheASP.NETcomponentsareeasilydistinguishablefromotherelementsonthepagebecausetheynormallyhave'

asp'

paintedonthetopleftcornerofthecontrols.Tobeginworkingwithdata,placeaDataGridcomponent,aBdpConnectioncomponent,andaBdpDataAdapteronthedesigner:

Figure3.AsamplesetupforanewWebform

Toconnecttoyourdatabase,right-clicktheBdpConnectionandselectConnectionEditor.Fromthismenu,selecttheAddbuttontoaddadataconnection.Thenselectthedatabaseyouwanttoconnecttoandcreateanametorepresenttheconnectiontothedatabase.Onmysystem,IamreturningalltheentriesofatablecalledPRODUCTLISTonmyDB28.1PersonaldatabasecalledSHOPPING(seeFigure4fortheconnectionparametersfortheBdpConnection).HereistheDDLforPRODUCTLIST:

CREATETABLE"

GLENN"

."

PRODUCTLIST"

"

PRODUCTCODE"

VARCHAR(20)NOTNULL,

PRODUCTNAME"

VARCHAR(50)NOTNULL,

DESCRIPTION"

VARCHAR(255),

UNITPRICE"

DOUBLENOTNULL,

CATEGORYCODE"

INTEGER,

IMAGEURL"

CHAR(150))

IN"

USERSPACE1"

;

COMMENTONTABLE"

IS'

AlistofProductsintheShoppingCart'

;

ALTERTABLE"

ADDCONSTRAINT"

CC1053568050795"

PRIMARYKEY

("

);

Aftercreatingthesettings,youwillalsoneedtoprovidetheconnectionsettingsforthedatabaseconnection.Oncetheconnectionsettingsaredefined,youshouldbeabletoclickontheTestbuttonintheConnectionsEditortofindoutifyoucanconnectsuccessfullyornot.

Figure4.TheConnectionseditorformallowsyoutopre-defineyourconnectiontothedatabase

Oncethesettingsaredefinedandyoucanconnecttothedatabase,youarereadytosetuptheBdpDataAdaptercomponent.LookingbackatFigure2,youcanseetherelationshipbetweentheBdpDataAdaptercomponentandtheBdpConnectionandtheBdpCommandobjects.

TheBdpDataAdapteristhepowerbrokerforworkingwiththeBDPcomponents.TheBdpDataAdapterconnectstothedatabaseviatheBdpConnectioncomponent.TheBdpDataAdaptercomponentalsohasfourBdpCommandproperties--SelectCommand,InsertCommand,UpdateCommand,andDeleteCommand.TheseBdpCommandsareusedtoperformtheretrievalandupdateoperationsagainstthedatabase.ThecommandthatrepresentstheSelectCommandisusedtoselectallthedatausedtopopulateaDataTable,whereastheotherthreeBdpCommandsareusedtorepresentthedatabaseoperationstoinsert,update,anddeleteasingleDataTablerow.

ThebasicconceptbehindtheBDPcomponentsisthattheBdpDataAdapterwillfilltheDataSetwithcontentfromyourdatabasesothatyoucanworkwiththeDataSet.TheDataSetshouldthenbedisconnectedfromtheBDPcomponents.WhentheDataSetneedstoretrievemoredataorupdatedata,itconnectsthroughtotheBdpDataAdapterwhenneeded.NowthatyouhavethebasicideaaboutthedataconnectivitytoDB2usingtheBDPcomponents,let'

sstartconnectingyourapplicationtosomedata.

PopulatingtheDataGrid

Todisplaythispresentation,usetheDataGridcomponentthatyouplacedontheWebForm.TobeabletoworkwiththeBdpDataAdapterindesigntime,youwillneedtosetActiveontheBdpDataAdaptercomponenttoTruesothatthegridwillbeabletoretrievetheschemainformationofthequerythatyouwillbeusing.

OncetheBdpDataAdapterisactive,selecttheDataGrid'

sPropertyBuilderoption.(Youcanfindthisoptionunderthepropertieslistinginthepropertyeditor.)YouwillbepresentedwithadialogthatdefinesthedataconnectivityandalsothedisplayaspectsoftheDataGrid.

Figure7.DefiningtheDataSet,theDataMember,andtheprimarykeyfortheDataMember

ThefirstoftheDataGrid'

sConfigurationoptionsdefinestheconnectiondetailstothedata,suchaswhichDataSetyouwillbeusingandwhichDataMember(DataTableorDataView)oftheDataSetyouwanttoview.YoualsoneedtodefinewhichfieldintheDataMemberisusedasthekeyfieldforthatDataView.

Atthispoint,thisisallyouneedtosetupthedatagrid.Inmostcases,though,youwillalsowanttodefinethecolumnsthatwillbedisplayedonthegrid.ByselectingtheColumnspagefortheDataGrid(seeFigure8),youcandefinewhichcolumnsyouwantdisplayed,altertheorderofthecolumns,andcustomizetheformattingofthecolumnheaderandofthecolumndata.Inmyexample,Iamjustrenamingtheheadersforeachofthefields,andstatingthattheUNITPRICEfieldshouldbedisplayedasacurrency.

Figure8.Customizingandformattingthecolumns

Nowallthatstandsbetweenyouandadata-drivenWebpageisafewlinesofcodethattelltheWebpagetobindthedatafromtheDataSettotheDataGrid.InASP.NET,componentswithdataconnectivityarenotconnectedbydefault.Instead,youmusttellthecodethatyouwanttobindtothedata.SointheWebForm'

sPage_Loadevent,usetheDataBindmethodoftheDataGridtotellittoconnectthroughtothedata:

privatevoidPage_Load(objectsender,System.EventArgse)

{

if(!

IsPostBack){

dataGrid1.DataBind();

}

}

ASP.NETusesamechanismcalledPostBacktomanagethestateoftheWebform.ThefirsttimeaWebpageisrequested,youwillinitializethepropertiesofyourWebForm.Whentheend-userconnectswiththedata,theyworkwiththesamepropertiesthathavebeenset,sothedataonlyneedstobeboundtothegridthefirsttimethepageisloaded.

OnceyouhaveaddedthecodetothePage_Loadevent,youarereadytorunyourWebapplication.Afterrunningthepage,youwillhaveaprofessional-lookingWebpagethatcontainsdynamicWebdata:

Figure9.YourDB2datadisplayedinyourWebbrowser

DataBinding--beyondthegrid

Nowthatyou'

vehadatasteofdatabinding,you'

regoing

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 党团工作 > 其它

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1