Tải bản đầy đủ - 0 (trang)
Part VII: Data Access with ASP.NET

Part VII: Data Access with ASP.NET

Tải bản đầy đủ - 0trang

Chapter20.ASP.NETDataControls

INTHISCHAPTER

AccessingDatainASP.NET3.5286

ASP.NETDataSourceControls286

ConfiguringaDataSourceControl289

OtherASP.NETDataControls293

Checkpoint298



AccessingDatainASP.NET3.5

Databaseaccessusedtobeafeatureonlyforlarge,enterprise

websites.Thatiscertainlynolongerthecase.Ontoday'sWeb,

databasesareusedformanypurposes,fromdisplayingdatato

userstostoringpagecontentforcontentmanagementsystems.

Sufficeittosaythatifyouaregoingtolearntobuildwebsites

fortoday'sInternet,youneedtounderstandhowtousedata

access.

Fortunately,dataaccessisnolongerjusttherealmof

programmers.Microsofthasputsubstantialeffortintomaking

ASP.NETarobusttoolforcreatingdataaccesswithminimal

code,andoftenwithnocodeatall.Muchofthisispossible

becauseoftheinclusionofdataprovidersandnewcontrolsto

facilitateeasyconnectivitytodatabases.

Note

Ifyouwanttoreadthetechnicaldetailsofthedata

providersavailableinthe.NETFramework3.5,read

msdn2.microsoft.com/enus/library/a6cd7c08(vs.90).aspx.

Inmanycases,displayingdatainASP.NETisaseasyas



droppingadatasourcecontrolontoyourpage,pointingitto

yourdatabase,andthendroppingadatacontrolontoyourpage

andpointingittothedatasourcecontrol.Infact,asyou'llsee

laterinthischapter,ASP.NETenablesyoutocreatevery

powerfuldata-enabledinterfaceswithoutwritinganycodeat

all.

Thefirststepinmakingawebsitedata-enabledistoaddadata

sourcecontroltothepage.Let'slookatthedatasource

controlsavailabletoASP.NETandhowtheyareconfigured.



PartVII:DataAccesswithASP.NET









20ASP.NETDataControls

21DisplayingDatafromaDatabase

22Adding,Editing,andDeletingRecords



Chapter20.ASP.NETDataControls

INTHISCHAPTER

AccessingDatainASP.NET3.5286

ASP.NETDataSourceControls286

ConfiguringaDataSourceControl289

OtherASP.NETDataControls293

Checkpoint298



AccessingDatainASP.NET3.5

Databaseaccessusedtobeafeatureonlyforlarge,enterprise

websites.Thatiscertainlynolongerthecase.Ontoday'sWeb,

databasesareusedformanypurposes,fromdisplayingdatato

userstostoringpagecontentforcontentmanagementsystems.

Sufficeittosaythatifyouaregoingtolearntobuildwebsites

fortoday'sInternet,youneedtounderstandhowtousedata

access.

Fortunately,dataaccessisnolongerjusttherealmof

programmers.Microsofthasputsubstantialeffortintomaking

ASP.NETarobusttoolforcreatingdataaccesswithminimal

code,andoftenwithnocodeatall.Muchofthisispossible

becauseoftheinclusionofdataprovidersandnewcontrolsto

facilitateeasyconnectivitytodatabases.

Note

Ifyouwanttoreadthetechnicaldetailsofthedata

providersavailableinthe.NETFramework3.5,read

msdn2.microsoft.com/enus/library/a6cd7c08(vs.90).aspx.

Inmanycases,displayingdatainASP.NETisaseasyas



droppingadatasourcecontrolontoyourpage,pointingitto

yourdatabase,andthendroppingadatacontrolontoyourpage

andpointingittothedatasourcecontrol.Infact,asyou'llsee

laterinthischapter,ASP.NETenablesyoutocreatevery

powerfuldata-enabledinterfaceswithoutwritinganycodeat

all.

Thefirststepinmakingawebsitedata-enabledistoaddadata

sourcecontroltothepage.Let'slookatthedatasource

controlsavailabletoASP.NETandhowtheyareconfigured.



PartVII:DataAccesswithASP.NET









20ASP.NETDataControls

21DisplayingDatafromaDatabase

22Adding,Editing,andDeletingRecords



Chapter20.ASP.NETDataControls

INTHISCHAPTER

AccessingDatainASP.NET3.5286

ASP.NETDataSourceControls286

ConfiguringaDataSourceControl289

OtherASP.NETDataControls293

Checkpoint298



AccessingDatainASP.NET3.5

Databaseaccessusedtobeafeatureonlyforlarge,enterprise

websites.Thatiscertainlynolongerthecase.Ontoday'sWeb,

databasesareusedformanypurposes,fromdisplayingdatato

userstostoringpagecontentforcontentmanagementsystems.

Sufficeittosaythatifyouaregoingtolearntobuildwebsites

fortoday'sInternet,youneedtounderstandhowtousedata

access.

Fortunately,dataaccessisnolongerjusttherealmof

programmers.Microsofthasputsubstantialeffortintomaking

ASP.NETarobusttoolforcreatingdataaccesswithminimal

code,andoftenwithnocodeatall.Muchofthisispossible

becauseoftheinclusionofdataprovidersandnewcontrolsto

facilitateeasyconnectivitytodatabases.

Note

Ifyouwanttoreadthetechnicaldetailsofthedata

providersavailableinthe.NETFramework3.5,read

msdn2.microsoft.com/enus/library/a6cd7c08(vs.90).aspx.

Inmanycases,displayingdatainASP.NETisaseasyas



droppingadatasourcecontrolontoyourpage,pointingitto

yourdatabase,andthendroppingadatacontrolontoyourpage

andpointingittothedatasourcecontrol.Infact,asyou'llsee

laterinthischapter,ASP.NETenablesyoutocreatevery

powerfuldata-enabledinterfaceswithoutwritinganycodeat

all.

Thefirststepinmakingawebsitedata-enabledistoaddadata

sourcecontroltothepage.Let'slookatthedatasource

controlsavailabletoASP.NETandhowtheyareconfigured.



ASP.NETDataSourceControls

AdatasourcecontrolisaspecialcontrolinASP.NETthat

providespowerfulcapabilitiestoyourpagewhenconnectingit

toadatabase.Datasourcecontrolsarenotvisiblewhenapage

isbrowsedinabrowser.Theirsolepurposeistomakea

connectionandcommunicatewithadatabase.

VisualWebDeveloper2008comeswithsixdifferentdatasource

controls.Thedatasourcecontrolsavailableareasfollows:

SqlDataSource

AccessDataSource

LinqDataSource

ObjectDataSource

XmlDataSource

SiteMapDataSource



SqlDataSourceControl

TheSqlDataSourcecontrolisusedtoconnecttoanydatabase

thatissupportedbythe.NETFrameworkdataengine.Youcan

usetheSqlDataSourcecontroltoconnecttoSQLServer

databases,MicrosoftAccessdatabases,Oracledatabases,and

manyotherdatabasetypes.However,theSqlDataSource

controlisoptimizedforusewithSQLServer.

Note

BysayingthatthecontrolisoptimizedforSQLServer,I

don'tmeantoimplythatit'snotarobustsolutionfor

otherdatabasetypes.Isimplymeanthatifyouare

usingaSQLServerdatabase,youshouldusethe

SqlDataSourcecontrolifpossible.



TouseaSqlDataSourcecontrol,simplydragitfromtheData

sectionofthetoolboxtoyourwebform.Whenyoudropitonto

apage,theCommonSqlDataSourceTaskspopupappears,as

showninFigure20.1.Toconfigurethedatasource,clickthe

ConfigureDataSourcelink.

Figure20.1.TheCommonSqlDataSourceTaskspopup

providesalinktomakeconfiguringthedatasourcea

simpletask.



Formoreonconfiguringadatasourcecontrol,see

"ConfiguringaDataSourceControl,"p.289.



AccessDataSourceControl

TheAccessDataSourcecontrolprovidessimpledataconnectivity

toanAccessdatabaselocatedwithinyourwebapplication.The

AccessDataSourcecontroldoesnotallowyoutospecifya

password,soasmentionedearlier,ifyourdatabaserequiresa

password,youneedtousetheSqlDataSourcecontrolto

connecttoit.



LinqDataSourceControl

TheLinqDataSourcecontrolistheonlydatasourcecontrolthat

isnewtoVisualWebDeveloper2008.LINQisanewtechnology

availableinthe.NETFramework3.5.LINQstandsforLanguage

IntegratedQueries.Essentially,it'sapowerfulmethodof

queryingdatadirectlyusingVBorC#,ratherthanusingthe

traditionalStructuredQueryLanguage(SQL)queries.

LINQisanadvancedprogrammingtopicthatwedon'tcoverin

thisbook,butyoucanreadplentyofinformationonusingLINQ

atmsdn2.microsoft.com/en-us/netframework/aa904594.aspx.

AnothergreatwebsiteforLINQinformationisHookedonLINQ,

availableatwww.hookedonlinq.com.



ObjectDataSourceControl

TheObjectDataSourcecontrolallowsyoutouseabusiness

objecttoqueryadatasource.AbusinessobjectcanbeaDLL

oraclassthatisdefinedintheApp_Codefolderofyourwebsite.

FormoreinformationontheApp_Codefolderand

otherspecialASP.NETfolders,see"SpecialFolders

inanASP.NETApplication,"p.116.



Usingabusinessobjecttoquerydataenablesyoutobuilda

multi-tieredapplicationthatprovidesalayerofabstraction

betweenyourASP.NETapplicationandyourdatasourcesothat



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Part VII: Data Access with ASP.NET

Tải bản đầy đủ ngay(0 tr)

×