Programming Microsoft SQL Server 2000 with Microsoft Visual Basic .Net - P9

Chia sẻ: Thanh Cong | Ngày: | Loại File: PDF | Số trang:50

0
57
lượt xem
11
download

Programming Microsoft SQL Server 2000 with Microsoft Visual Basic .Net - P9

Mô tả tài liệu
  Download Vui lòng tải xuống để xem tài liệu đầy đủ

Tham khảo tài liệu 'programming microsoft sql server 2000 with microsoft visual basic .net - p9', công nghệ thông tin, cơ sở dữ liệu phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả

Chủ đề:
Lưu

Nội dung Text: Programming Microsoft SQL Server 2000 with Microsoft Visual Basic .Net - P9

  1. • • End Sub • • • Private Sub Button1_Click(ByVal sender As System.Object, _ • ByVal e As System.EventArgs) Handles Button1.Click • • ’Move to first row and populate text boxes. • Session(“MyRowID”) = 0 • MoveToRow() • • End Sub • • Private Sub Button2_Click(ByVal sender As System.Object, _ • ByVal e As System.EventArgs) Handles Button2.Click • • ’Move to previous row and populate text boxes. • If Session(“MyRowID”) > 0 Then • Session(“MyRowID”) -= 1 • End If • MoveToRow() • • End Sub • • • Private Sub Button3_Click(ByVal sender As System.Object, _ • ByVal e As System.EventArgs) Handles Button3.Click • • ’Move to next row and populate text boxes. • If Session(“MyRowID”) < _ • Ds1.Tables(“Products”).Rows.Count - 1 Then • Session(“MyRowID”) += 1 • End If • MoveToRow() • • End Sub • • • Private Sub Button4_Click(ByVal sender As System.Object, _ • ByVal e As System.EventArgs) Handles Button4.Click • • ’Move to last row and populate text boxes. • Session(“MyRowID”) = Ds1.Tables(“Products”).Rows.Count - 1 • MoveToRow() • • End Sub • Cr e a t in g D a t a ba se Obj e ct s fr om W e b Pa ge s Your applicat ions will som et im es need t he availabilit y of cust om dat abase obj ect s. For exam ple, st or ed pr ocedur es, w hich st ore pr ecom piled, opt im ized SQL code, are great for m anaging dat a m anipulat ion t asks, such as insert ing new records Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  2. int o a t able, and dat a definit ion t asks, such as dynam ically creat ing a new t able. I f you happen t o creat e a cust om t able for y our applicat ion, y our applicat ion can probably also benefit from one or m or e st ored procedur es perform ing dat a m anipulat ion t asks for t he t able. For exam ple, your applicat ion can pass t he st ored procedure param et ers specify ing t he colum n values for a new row, and t he st ored procedure can ex ecut e t he I NSERT I NTO st at em ent . I f your applicat ion needs t he value for a colum n w it h an I dent it y propert y cr eat ed on t he SQL Ser ver inst ance, t he st ored procedure can r et ur n it as an out put param et er . The sam ple for t his sect ion dem onst rat es t he cr eat ion of a t able and a st or ed procedur e. The sam ple is t he set up program for t he next sect ion t hat dem onst rat es how t o pr ogram dat a m anipulat ion t asks. Specifically , y ou w ill lear n how t o creat e a t able and a st or ed pr ocedur e on a SQL Serv er inst ance from an ASP.NET applicat ion. Figur e 11- 20 shows t he Web page for t he sam ple. The page’s nam e is WebFr om 1.aspx, and it r esides in t he Set upForWebUpdat eSam ple proj ect . The page includes t wo but t ons and a hy per link. The but t ons have Text propert y set t ings r eflect ing t he t ext t hey show. The but t on I D propert y set t ings are But t on1 for t he t op but t on and But t on2 for t he one below it . The hy per link cont r ol has t wo design- t im e pr opert y set t ings. First , it s Text propert y specifies t he m essage t o display when rendered on a Web page. Second, t he Navigat eUr l propert y designat es t he URL of t he page t o w hich t o pass cont r ol w hen a user clicks t he hyper link. I f y ou ar e running t he applicat ion against anot her Web serv er besides t he local one on y our workst at ion, y ou w ill need t o updat e t he Nav igat eUr l pr opert y for t he hyper link cont r ol. Figu r e 1 1 - 2 0 . W eb For m 1 .a spx in t h e Set u pFor W e b Upda t e Sa m p le p roj ect . The sam ple’s new t able is essent ially a scrat ch copy of t he Shippers t able in t he Nort hwind dat abase. By creat ing a scrat ch copy of t he t able, y ou w ill be able t o m ake changes against t he new sam ple t able w it hout dest roy ing t he or iginal dat a in t he sam ple dat abase. The But t on1_Click event pr ocedur e per form s t hr ee subt asks as it creat es a new t able nam ed ASPNETShippers. First it r em ov es t he ASPNETShippers t able if it already ex ist s in t he dat abase. Next it creat es t he ASPNETShippers t able. Third it populat es t he r ows of t he ASPNETShippers t able wit h rows from t he Shippers t able. Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  3. The list ing t hat follows st art s by declar ing and inst ant iat ing a SqlConnect ion obj ect ( cnn1) and a SqlCom m and obj ect ( cm d1) . By declaring t he obj ect s at t he m odule lev el, I can use t hem in ev ent pr ocedur es for each but t on in Figure 11- 20. The But t on1_Click event pr ocedur e st art s by specifying t he connect ion st r ing for cnn1 and opening t he obj ect . Next t he pr ocedur e assigns cnn1 t o t he Connect ion pr opert y for cm d1, t he SqlCom m and obj ect . Aft er t hese pr elim inary st eps, t he procedure successively r epeat s t w o st at em ent s for assigning a Com m andText propert y t o cm d1 and t hen inv oking t he Execut eNonQuery m et hod for cm d1. Apply t he Execut eNonQuery m et hod of a SqlCom m and obj ect when t he obj ect ’s Com m andText propert y doesn’t r et ur n a r esult set . The t hr ee Com m andText propert y set t ings r em ov e any pr ior version of t he ASPNETShippers t able, cr eat e a new ASPNETShippers t able, and populat e t he ASPNETShippers t able w it h r ows from t he Shippers t able in t he Nort hw ind dat abase. The But t on1_Click ev ent pr ocedur e concludes by closing cnn1. The logic for t he But t on2_Click ev ent procedur e follows t he sam e basic design as t hat in t he But t on1_Click ev ent pr ocedur e. The ov erall process is: ( 1) m ak e a connect ion, ( 2) run one or m ore SQL st at em ent s wit h a SqlCom m and obj ect , and ( 3) close t he connect ion. The obj ect iv e of t he But t on2_Click ev ent pr ocedur e is t o creat e a new st or ed pr ocedure nam ed udpI nsert ANew ASPNETShipper . The ev ent procedur e ex ecut es t wo SQL st at em ent s t o achiev e t his obj ect iv e. First it runs one st at em ent t o rem ov e any pr ior v ersion of t he connect ion in t he Nort hw ind dat abase. Second it runs a procedur e t o cr eat e a new version of t he udpI nsert ANew ASPNETShipper st or ed procedur e. We discussed t he logic for t his st ored procedure in Chapt er 10. That chapt er dem onst rat ed how t o cr eat e t he st ored procedure in Query Analyzer and discussed t he logic t hat t he SQL st at em ent s express. This chapt er ext ends t he earlier t r eat m ent of t he t opic by dem onst rat ing how t o creat e t he st ored procedur e program m at ically fr om w it hin ASP.NET. N ot e For dat a definit ion SQL st at em ent s t o funct ion proper ly , such as t hose in t he But t on1_Click and But t on2_Click event procedures, you m ust r un t hem fr om a login wit h appropr iat e per m ission t o creat e dat abase obj ect s on t he SQL Ser ver inst ance t o which you connect . See Chapt er 7 for det ailed coverage of SQL Ser ver secur it y, including logins and per m issions. Alt ernat ively, y ou can use t he SQL Serv er sa login. Howev er, t his is poor applicat ion design because it allows user s unrest r ict ed aut horit y on a SQL Server. Dim cnn1 As New SqlClient.SqlConnection()Dim cmd1 As New SqlClient.Sq lCommand() Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click ’Make connection to northwind database. cnn1.ConnectionString = “Data Source=(local);” & _ “Initial Catalog=northwind;” & _ “Integrated Security=SSPI" cnn1.Open() ’Assign connection to cmd1. cmd1.Connection = cnn1 ’Execute query to drop prior version of table. Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  4. cmd1.CommandText = “IF EXISTS (“ & _ “SELECT * FROM INFORMATION_SCHEMA.TABLES “ & _ “WHERE TABLE_NAME = ’ASPNETShippers’) “ & _ “DROP TABLE dbo.ASPNETShippers" cmd1.ExecuteNonQuery() ’Execute query to create new version of table. cmd1.CommandText = “CREATE TABLE dbo.ASPNETShippers “ & _ “(“ & _ “ShipperID int IDENTITY (1, 1) NOT NULL, “ & _ “CompanyName nvarchar (40) NOT NULL, “ & _ “Phone nvarchar (24) NULL, “ & _ “CONSTRAINT PK_ASPNETShippers “ & _ “PRIMARY KEY CLUSTERED (ShipperID)” & _ “)" cmd1.ExecuteNonQuery() ’Populate table based on Shippers. cmd1.CommandText = _ “SET IDENTITY_INSERT dbo.ASPNETShippers ON “ & _ “INSERT INTO ASPNETShippers “ & _ “(ShipperID, CompanyName, Phone) “ & _ “SELECT * FROM Shippers “ & _ “SET IDENTITY_INSERT dbo.ASPNETShippers OFF" cmd1.ExecuteNonQuery() cnn1.Close() End Sub Private Sub Button2_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button2.Click ’Make connection to northwind database. cnn1.ConnectionString = “Data Source=(local);” & _ “Initial Catalog=northwind;” & _ “Integrated Security=SSPI" cnn1.Open() ’Assign connection to cmd1. cmd1.Connection = cnn1 ’Drop any prior version of udpInsertANewASPNETShipper. cmd1.CommandText = “IF EXISTS (“ & _ “SELECT ROUTINE_NAME “ & _ “FROM INFORMATION_SCHEMA.ROUTINES “ & _ “WHERE ROUTINE_TYPE = ’PROCEDURE’ AND “ & _ “ROUTINE_NAME = ’udpInsertANewASPNETShipper’) “ & _ “DROP PROCEDURE dbo.udpInsertANewASPNETShipper" cmd1.ExecuteNonQuery() ’Create a new version of udpInsertANewASPNETShipper. cmd1.CommandText = _ “CREATE PROCEDURE udpInsertANewASPNETShipper “ & _ “@CompanyName nchar(40), “ & _ “@Phone nvarchar (24), “ & _ “@Identity int OUT “ & _ “AS “ & _ “INSERT INTO ASPNETShippers “ & _ “(CompanyName, Phone) “ & _ Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  5. “VALUES(@CompanyName, @Phone) “ & _ “SET @Identity = SCOPE_IDENTITY()" cmd1.ExecuteNonQuery() cnn1.Close() End Sub D a t a M a n ipu la t ion fr om ASP.N ET Aft er running t he applicat ion in t he pr eceding sect ion, y ou w ill hav e a new copy of t he ASPNETShippers t able in t he Nort hw ind dat abase as well as a st ored procedur e, udpI nsert ANew ASPNETShipper, t o facilit at e insert ing new r ows int o t he ASPNETShippers t able. The sam ple applicat ion in t his sect ion illust r at es how t o m odify, insert , and delet e rows in t he ASPNETShippers t able fr om an ASP.NET applicat ion. The applicat ion builds on t he browsing sam ple illust rat ed by t he WebForm 1.aspx page in t he NavText Boxes proj ect . The addit ion of dat a m anipulat ion t o t hat earlier applicat ion is part icular ly int er est ing because t hat applicat ion used an unbound form t o display colum n values fr om t he Shippers t able. I n ot her w ords, t he form field values don’t bind t o any dat a sour ce. Ther efor e, all dat a m anipulat ion t asks m ust be perform ed in code. The sam ple in t his sect ion is im port ant for anot her r eason. The applicat ion enables users t o updat e a SQL Ser ver dat abase ov er t he Web. N ot e As wit h t he sam ple in t he preceding sect ion, users of t his applicat ion m ust hav e perm ission t o perfor m a t ask befor e t he applicat ion aut om at ing t hat t ask will work . I n t his sect ion, t he t asks are t he classic t hree dat a m anipulat ion ones of m odify ing, inser t ing, and delet ing r ecords. W e b Pag e Layou t a nd Ope ra t ion Figur e 11- 21 shows t he Web page lay out for t his applicat ion. The page’s nam e is WebForm 1.aspx in t he Updat eWit hWebForm pr oj ect . Except for four new but t ons at t he bot t om of t he page, t he page layout look s sim ilar t o t he one in Figur e 11- 18 for browsing r ecords wit h t ext box cont r ols. The four new but t ons facilit at e changes t o t he row current ly appear ing on t he Web page, delet e t he r ow curr ent ly appear ing, and clear t he fields and insert a new row int o t he dat abase based on new form field values. The Web page in Figur e 11- 21 connect s t o t he ASPNETShippers, inst ead of t he Shippers, t able in t he Nort hw ind dat abase. This dist inct ion enables applicat ion users of t he sam ple in t his sect ion t o m anipulat e t he dat a appearing on t he Web page wit hout changing t he original dat a in t he sam ple dat abase. By cont rast ing t he Design v iews of t he t wo pages, y ou w ill also not ice t hat t he new Web page has no ADO. NET obj ect s creat ed at design t im e. You can t ell t his because t he syst em t ray doesn’t appear in Figur e 11- 21. Figu re 1 1 - 2 1 . W eb For m 1 .a spx in t h e Upda t eW it h W e bForm p roj e ct . Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  6. The ent ire r eason for t his sam ple is t o dem onst r at e t hat y ou can enable dat a m anipulat ion t asks from a Web page w it h ASP.NET. Figure 11- 22 st art s t o dem onst rat e t his capabilit y by show ing t wo v iews of t he Web page in operat ion. The t op w indow shows t he Web page aft er a click of t he Clear but t on ( it s nam e is cm dClear ) and t hen t he addit ion of new t ext in t wo of t he t ex t box es. The cm dClear but t on clears t he form on t he Web page so t he user can ent er a new row of dat a. I n t his t op window, y ou can see t hat t he Com panyNam e and Phone values for a new shipper hav e been ent ered but t hat t he t op t ext box for ShipperI D is em pt y . That ’s because t he SQL Serv er inst ance assigns a value t o t his field. Click ing t he I nsert but t on ( it s nam e is cm dI nsert ) changes t he browser t o look lik e t he w indow in t he bot t om port ion of Figur e 11- 22. Not ice t hat t he Com panyNam e and Phone t ext box es ar e t he sam e. However, you now hav e a ShipperI D t ext box value. SQL Serv er generat ed t his value on t he serv er , and t he Updat eWit hWebForm applicat ion ret riev ed t he v alue by capt ur ing t he ret ur n param et er value from t he udpI nsert ANew ASPNETShipper st or ed procedur e. Figu re 1 1 - 2 2 . W eb For m 1 .a spx in t h e Upda t e W it h W e bForm p roj e ct be for e a n d aft e r com m it t ing a n in se rt t o t h e ASPN ETSh ipp e rs t a ble. Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  7. Figur e 11- 23 shows t he row ent er ed in t he pr eceding sam ple in t he process of being m odified. Not ice t hat t he user changed t he last digit in t he t elephone num ber from 7 t o 8. The applicat ion doesn’t com m it t his change unt il t he user clicks t he Modify but t on. ( I t s nam e is cm dModify.) Aft er t he user clicks cm dModify , t he applicat ion conveys t he new value t o t he SQL Ser ver inst ance and refr eshes t he local copy of t he dat a set on t he Web page w it h t he t able of values from t he SQL Serv er inst ance. Figu r e 1 1 - 2 3 . W e bFor m 1 .a spx in t h e Upda t e W it h W eb For m pr oj e ct j u st be for e a m od ifica t ion t o t h e t eleph on e n um be r for t h e r ow ad de d in Figu re 1 1 - 2 2 . Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  8. Figur e 11- 24 shows t he Delet e but t on ( it s nam e is cm dDelet e) in operat ion. I n t he t op w indow, you can see t he new r ow w it h it s edit ed Phone value. The cursor rest s on t he cm dDelet e but t on. Click ing t his but t on r em oves t he r ow appearing on t he Web page fr om t he ASPNETShippers t able in t he SQL Serv er inst ance and updat es t he dat a set on t he Web page t o r eflect t his r esult . Because t he click t o t he cm dDelet e but t on r em oved t he form er last row in t he Shippers dat a set , t he Web page shows t he new last row w it h a ShipperI D colum n value of 3. The Click ev ent procedure behind t he cm dDelet e but t on m anages t he display of which row appears on t he page aft er t he rem oval of a row . For exam ple, if a user r em oved t he first r ow ( wit h a ShipperI D colum n value of 1) , t he row appear ing on t he Web page would be t he new first row in t he dat a set wit h a ShipperI D value of 2. Figu r e 1 1 - 2 4 . W e bFor m 1 .a spx in t h e Upda t e W it h W eb For m pr oj e ct j u st be for e a n d j u st a ft er t h e r em ova l of t h e r ow t h a t h a d it s Ph on e valu e ed it e d in Figu r e 1 1 - 2 3 . Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  9. Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  10. Code Be h ind t h e W eb Pa ge The code for perform ing dat a m anipulat ion on a Web page parallels t hat for perform ing dat a m anipulat ion in a Windows for m . How ev er, one im port ant difference is t hat in a Windows for m , y our code has t o cr eat e m ost of t he ADO.NET obj ect s, such as a SqlDat aAdapt er and a dat a set , j ust once. I n t he case of a Web applicat ion, your code w ill t ypically have t o re- cr eat e t hese obj ect s each t im e a Web page does a round- t r ip bet ween a browser and a Web serv er— for exam ple, ev er y t im e t he user clicks a but t on on t he Web page. As m ent ioned prev iously , y ou should k eep t he size of t he dat a set on a Web page sm all for t his reason. I n our case, t he ASPNETShippers t able is alr eady a sm all t able of j ust t hr ee original r ows. I f y our or iginal dat a source is large, consider pulling dow n j ust a sm all port ion of it on successive r ound- t r ips by using a st or ed pr ocedur e or a user - defined funct ion t hat ret ur ns a cust om izable r esult set based on input t hat you pass it t hr ough a param et er . The follow ing list ing includes t hose part s of t he code behind t he Web page t hat pert ain direct ly t o t he dat a m anipulat ion part of t he sam ple. The dat a display and nav igat ion code closely follow t he code appear ing in t he sect ion t it led “Nav igat ing Text Box es Through a Dat a Set ”. I n order t o conserve space in t his book for fr esh inform at ion, I direct y ou t o t he code sam ples for t his book, where t he com plet e list ing is available for t he code behind t he Web page. The list ing st art s by declar ing and inst ant iat ing at t he m odule level four ADO.NET obj ect s: a SqlConnect ion obj ect ( cnn1) , a SqlCom m and obj ect ( cm d1) , a SqlDat aAdapt er obj ect ( dap1) , and a Dat aSet obj ect ( das1) . The Page_Load ev ent procedure uses each of t hese obj ect s, and t he obj ect s find select iv e use in ot her event procedures t hr oughout t he code behind t he page. Aft er m ak ing a connect ion t o t he Nort hw ind dat abase, t he Page_Load event procedur e declares t he dap1 dat a adapt er dependent on all t he colum ns from all t he r ows of t he ASPNETShippers t able. Next t he procedure defines t he Updat eCom m and propert y for t he dat a adapt er. A SQL UPDATE st at em ent wit h param et ers specifies t he it em s t o updat e. Aft er t he SQL st at em ent for t he Updat eCom m and propert y, t w o addit ional st at em ent s add param et ers t o t he com m and for t he Updat eCom m and pr opert y. These param et ers allow t he Web page t o pass values from t he ent r ies in it s t ext boxes. The next param et er is for t he t ext box holding a ShipperI D value on t he Web page. Whereas t he param et er t ies t o t he ShipperI D v alue in t he dat a set behind t he Web page, it uses t he row curr ent ly appear ing in t he first t ext box on t he Web page. The next sev er al lines of code in t he Page_Load ev ent procedure define t he I nsert Com m and propert y for t he dap1 dat a adapt er and it s associat ed param et ers. I n t his case, t he procedur e designat es t he perform ance of t he insert via t he udpI nsert ANew ASPNETShipper st or ed pr ocedur e. Recall t hat t he preceding sect ion dem onst rat ed how t o creat e t his st ored pr ocedur e in t he code behind a separat e st and- alone Web page. The st at em ent s adding param et ers illust rat e t he synt ax for passing param et ers t o a st ored pr ocedur e and capt uring a ret ur n value fr om a st or ed pr ocedur e. Not ice t hat you designat e a Dir ect ion propert y for prm 2 w it h t he Param et erDirect ion.Out put enum erat ion value. This param et er ( prm 2) ret ur ns t he I dent it y value for t he insert ed r ow by t he SQL Ser ver inst ance. The next block of code in t he Page_Load event procedur e defines t he Delet eCom m and pr oper t y and it s param et er for t he dap1 obj ect . This block of code uses a SQL DELETE st at em ent t o designat e w hich row t o dr op from t he ASPNETShippers t able along wit h t he r ow ’s copy in t he dat a set behind t he Web page. Because t he ShipperI D value is t he pr im ary key of t he ASPNETShippers t able, t he code uniquely ident ifies a row t o r em ov e from t he t able by specify ing a value for t his colum n. Aft er defining t he dap1 dat a adapt er and it s dat a m anipulat ion propert ies, t he Page_Load ev ent procedure perform s t wo m ore essent ial t asks. First t he Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  11. procedur e fills t he das1 dat a set wit h t he values fr om t he ASPNETShippers t able. Second t he procedur e populat es t he t ext boxes on t he page w it h values fr om t he first row of t he das1 dat a set . Users m ake a change by m odify ing t he Com panyNam e or Phone t ext box values on t he Web page and t hen clicking t he cm dModify but t on. I n t he Click event for t his but t on, t he pr ocedure declar es and inst ant iat es a dat a v iew ( dav1) based on t he ASPNETShippers Dat aTable in t he das1 dat a set . The pr ocedur e defines a sort key for dav1 based on t he ShipperI D colum n. Then t he pr ocedur e uses t he dat a view’s Find m et hod t o ret ur n t he row index for t he r ow wit h a ShipperI D colum n value m at ching t he cur rent ShipperI D v alue display ed on t he Web page. Defining t he sort key is a necessary st ep for using t he Find m et hod ( because t he ASPNETShippers Dat aTable in das1 doesn’t hav e a pr im ary key const raint ) . Wit h t he index r eflect ing t he row display ed on t he Web page, t he pr ocedur e creat es a Dat aRow based on t he dat a t able’s schem a and dat a t hat point s t o t he row from t he dat a t able displayed on t he Web page. Then t he pr ocedur e updat es t he r ow’s colum n values w it h t hose from t he Web page. This m odifies t he dat a t able. Finally t he procedure closes by inv ok ing t he Updat e m et hod for t he dap1 dat a adapt er . This m et hod t ransfers t he changes from t he local t able t o t he m at ching one on t he SQL Serv er inst ance. The cm dClear and cm dI nsert but t ons w or k t oget her. I n general, a user should click t he cm dClear but t on before click ing t he cm dI nsert but t on. The cm dClear but t on’s Click ev ent pr ocedur e blanks t he t ext box cont r ols on t he Web page. Next t he user should insert v alues in t hose blank cont rols. The Click ev ent procedur e for t he cm dI nsert but t on declar es a new r ow t o add t o t he ASPNETShippers dat a t able and t hen populat es t he r ow wit h values fr om t ext boxes on t he Web page. At t his point , updat ing t he local dat a t able is as easy as inv ok ing t he Add m et hod. This st ep appends t he new row t o t he end of t he ASPNETShippers dat a t able. Nex t t he procedur e inv okes t he Updat e m et hod t o upload t he new r ow t o t he ASPNETShippers t able in t he SQL Serv er inst ance and t o dow nload t he ShipperI D value creat ed on t he SQL Ser ver inst ance. The out put param et er st at em ent s for t he dap1 I nsert Com m and propert y in t he Page_Load ev ent procedure aut om at ically assure t he proper handling of t he r et ur n value from t he udpI nsert ANewASPNETShipper st or ed procedure. Finally t he procedur e updat es t he My RowI D Session variable t o point t o t he last r ow in t he dat a t able and shows t his r ow ( wher e ADO.NET perform s t he insert ) on t he Web page. N ot e The cm dModify but t on Click event procedure doesn’t updat e t he MyRowI D Session variable or t he values on t he Web page. At t he end of t he m odify updat e, t he corr ect row alr eady appears on t he Web page. Therefor e, t her e is no need t o show anot her record. The cm dDelet e_Click ev ent pr ocedur e borr ows from t he logic of t he t wo preceding ev ent procedures and adds a new w rinkle or t w o. First t he procedure defines a dat a view t o find an index value for t he row display ed on t he Web page, w hich is t he r ow a user want s t o delet e. The second st ep is new . I n t his st ep, t he procedur e inv ok es t he Delet e m et hod for t he r ow in t he dat a t able t hat m at ches t he r ow displayed on t he Web page. This m et hod doesn’t physically rem ov e t he row from t he local dat a t able. I nst ead, it m ark s t he r ow for delet ion. When t he procedur e inv ok es t he Updat e m et hod in t he t hird st ep, it finds all r ows m ark ed for delet ion and rem ov es t hem fr om t he SQL Serv er version of t he ASPNETShippers t able. I n t his applicat ion, t her e w ill always be j ust one such r ow. Aft er rem ov ing t he row on t he serv er , t he Updat e m et hod aut om at ically r em ov es t he r ow locally. This t im e t he pr ocedure physically r em oves t he r ow fr om t he local dat a t able. Aft er com plet ing t he delet ion, t he pr ocedur e displays on t he Web page Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  12. t he prev ious row before t he one j ust delet ed. I f t hat row ( t he one j ust delet ed) was t he first row, t he pr ocedur e shows t he old second r ow, w hich is t he new first row . Dim cnn1 As New SqlClient.SqlConnection()Dim cmd1 As New SqlClient.Sq lCommand() Dim dap1 As New SqlClient.SqlDataAdapter() Dim das1 As New DataSet() Private Sub Page_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load ’Make connection to northwind database and ’point data adapter (dap1) at it cnn1.ConnectionString = “Data Source=(local);” & _ “Initial Catalog=northwind;” & _ “Integrated Security=SSPI" dap1 = _ New SqlClient.SqlDataAdapter( _ “SELECT * FROM ASPNETShippers", cnn1) ’Set the UpdateCommand property for dap1. dap1.UpdateCommand = _ New SqlClient.SqlCommand _ (“UPDATE ASPNETShippers “ & _ “SET CompanyName = @CompanyName, “ & _ “Phone = @Phone “ & _ “WHERE ShipperID = @ShipperID", _ cnn1) ’Add two parameters that take source columns ’from the ASPNETShippers table in the dataset for the ’dap1 adapter and feed the parameters in the SQL ’string for the UpdateCommand property. dap1.UpdateCommand.Parameters.Add _ (“@CompanyName", SqlDbType.NVarChar, 40, _ “CompanyName”) dap1.UpdateCommand.Parameters.Add _ (“@Phone", SqlDbType.NVarChar, 24, _ “Phone”) ’Specify matching criterion values based on the ’original version of the ShipperID column in the ’local ASPNETShippers table. Dim prm1 As SqlClient.SqlParameter = _ dap1.UpdateCommand.Parameters.Add _ (“@ShipperID", SqlDbType.Int) prm1.SourceColumn = “ShipperID" prm1.SourceVersion = DataRowVersion.Original ’Point InsertCommand at a SQL Server stored procedure; ’you must have the stored procedure on the server. dap1.InsertCommand = New _ SqlClient.SqlCommand(“udpInsertANewASPNETShipper", cnn1) dap1.InsertCommand.CommandType = CommandType.StoredProcedure ’Specify input parameters for the stored procedure. dap1.InsertCommand.Parameters.Add _ (“@CompanyName", SqlDbType.NVarChar, 40, _ “CompanyName”) dap1.InsertCommand.Parameters.Add _ (“@Phone", SqlDbType.NVarChar, 24, _ Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  13. “Phone”) ’Designate an output parameter for the identity ’value assigned within SQL Server so that your ’local ASPNETShippers table can have a matching ’ShipperID column value. Dim prm2 As SqlClient.SqlParameter = _ dap1.InsertCommand.Parameters.Add _ (“@Identity", SqlDbType.Int, 0, “ShipperID”) prm2.Direction = ParameterDirection.Output ’Specify the SQL string for the DeleteCommand ’property of dap1. dap1.DeleteCommand = _ New SqlClient.SqlCommand(“DELETE “ & _ “FROM ASPNETShippers “ & _ “WHERE ShipperID = @ShipperID", cnn1) ’Specify matching criterion values based on the ’original version of the ShipperID column in the ’local ASPNETShippers table. Dim prm3 As SqlClient.SqlParameter = _ dap1.DeleteCommand.Parameters.Add _ (“@ShipperID", SqlDbType.Int) prm3.SourceColumn = “ShipperID" prm3.SourceVersion = DataRowVersion.Original ’Fill dataset. das1 = New DataSet() dap1.Fill(das1, “ASPNETShippers”) ’On initial page load move to first row and ’populate text boxes; this code segment must ’appear after you create the local ASPNETShippers ’table. If Not Me.IsPostBack Then Session(“MyRowID”) = 0 MoveToRow() End If End Sub Private Sub cmdModify_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles cmdModify.Click ’Use dav1 to find the row in ASPNETShippers ’that appears in the text boxes from the local ’ASPNETShippers table. Dim dav1 As DataView = _ New DataView(das1.Tables(“ASPNETShippers”)) dav1.Sort = “ShipperID" Dim rowindex As Integer = _ dav1.Find(TextBox1.Text) ’Create a DataRow object pointing at the row ’to update in the local table. Dim IndexedRow As DataRow = _ das1.Tables(“ASPNETShippers”).Rows(rowindex) ’Update the local table with the text boxes. Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  14. IndexedRow(“CompanyName”) = TextBox2.Text IndexedRow(“Phone”) = TextBox3.Text ’Invoke Update method for dap1 to synchronize ’the local table with the one in northwind. dap1.Update(das1, “ASPNETShippers”) End Sub Private Sub cmdClear_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles cmdClear.Click ’Clear text boxes for data entry. TextBox1.Text = “" TextBox2.Text = “" TextBox3.Text = “" End Sub Private Sub cmdInsert_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles cmdInsert.Click ’Add text box values to new row in dataset Shippers table. Dim newRow As DataRow = das1.Tables(“ASPNETShippers”).NewRow() newRow(“CompanyName”) = TextBox2.Text newRow(“Phone”) = TextBox3.Text das1.Tables(“ASPNETShippers”).Rows.Add(newRow) ’Update method synchronizes inserted local row ’with its copy in northwind and returns the identity ’column value added by the northwind database. dap1.Update(das1, “ASPNETShippers”) ’Move to last row and populate text boxes. Session(“MyRowID”) = das1.Tables(“ASPNETShippers”).Rows.Count - 1 MoveToRow() End Sub Private Sub cmdDelete_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles cmdDelete.Click ’Create a dataview based on the ASPNETShippers table ’in the dataset and find the row index that matches ’the current ShipperID. Dim dav1 As DataView = _ New DataView(das1.Tables(“ASPNETShippers”)) dav1.Sort = “ShipperID" Dim rowIndex As Integer = _ dav1.Find(TextBox1.Text) ’Mark the row for deletion in the dataset. das1.Tables(“ASPNETShippers”).Rows(rowIndex).Delete() ’Invoke the Update method to complete the deletion ’in both the SQL Server and dataset Shippers tables. dap1.Update(das1, “ASPNETShippers”) Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  15. ’Move to previous row and populate textboxes. If Session(“MyRowID”) > 0 Then Session(“MyRowID”) -= 1 End If MoveToRow() End Sub Va lida t ing t h e D a t a on a W eb Pa ge ASP.NET int roduces som e powerful cont r ols for facilit at ing v alidat ion of t he dat a in cont r ols on Web pages. You can use t hese power ful cont rols graphically or bot h graphically and pr ogr am m at ically . This sect ion int r oduces you t o t he cont rols ov erall and t hen pr esent s a series of t hr ee sam ples t o dem onst rat e how t o apply validat or cont rols in y our Web applicat ions. Bu ilt - I n D a t a Va lida t ion Tools ASP.NET offers five special Web ser ver cont r ols t o facilit at e validat ing t he dat a users ent er int o ot her cont rols on a Web page. You can use t hese special Web serv er cont rols w it hout any program m ing, or y ou can use t he Page obj ect m odel for pr ogram m at ically responding t o t he validat ion cont rols indiv idually or collect ively. I n addit ion, t he fiv e validat ion cont rols enable y ou t o dict at e how t o display err ors. Basically , t her e ar e t wo display opt ions wit h som e var iat ions in bet ween. First , you can show er r or m essages indiv idually near t he cont rols t o which t he m essages apply. Second, y ou can choose t o display er ror m essages collect ively in a cent ral area. You can drag t o a Web page any of t he fiv e t ypes of validat or Web serv er cont rols from t he Web Form s t ab on t he Toolbar . For each cont rol, y ou m ust specify t he Cont rolToValidat e pr opert y, which designat es t he cont r ol t o w hich t he Web serv er validat or cont rol applies. You can opt ionally specify a cust om er ror m essage or accept t he default error m essage associat ed w it h t he validat or cont r ol, and select ed validat or cont r ols m ay hav e ot her m andat ory or opt ional pr opert ies t o set . Br ief sum m aries of t he fiv e t ypes of v alidat or cont rols appear below. • The RequiredFieldValidat or cont rol det ect s a m issing value for a validat ed cont r ol. This is t he only validat or cont rol t hat checks for em pt y cont r ols, and y ou m ight t her efore want t o use Requir edFieldValidat or cont rols w it h ot her Web serv er validat or cont r ols. • The Com par eValidat or cont rol uses a com par ison operat or, such as less t han, equal t o, or gr eat er t han, t o det erm ine how a pr opert y for a t arget cont r ol com pares w it h anot her value. You can also use Com pareValidat or t o check t he dat a t ype of an ent ry . • The RangeValidat or cont rol can check t o ensur e t hat a t arget cont rol’s propert y is in a specified range. This validat or cont rol let s y ou set low er and upper boundary values for validat ing a cont rol. • The RegularExpr essionValidat or cont r ol enables you t o check t hat ent r ies follow a pat t er n, such as for t elephone num ber s or social secur it y num bers. The Validat ionExpression pr opert y in t he Propert ies window for t his v alidat or cont rol offers a select ion of prespecified regular expr essions for such ent r ies as phone num ber, post al code, e- m ail addr ess, and social secur it y num ber. I n addit ion, you can pr ogram cust om r egular expressions. Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  16. • Wit h t he Cust om Validat or cont rol, y ou can dev elop cust om checks for dat a t hat ar en’t covered by t he pr eceding cont rols. You hav e sev eral display opt ions for showing error m essages associat ed wit h t he Web serv er validat or cont r ols. Assign a st ring t o t he Err or Message pr opert y for a validat or cont rol t o specify a cust om err or m essage, such as “Ent er a com pany,” inst ead of a default m essage, w hich happens t o be “RequiredFieldValidat or,“ t he sam e t ext as t he nam e of t he cont rol t ype. The error m essages associat ed w it h a validat or cont rol w ill alw ays appear where y ou place t he cont r ol on a Web page unless you also add a Validat ionSum m ar y cont r ol t o t he page. Wit h a Validat ionSum m ar y cont rol on a page, you can hav e er ror m essages appear collect ively in t he Validat ionSum m ar y cont r ol by assigning an HTML charact er, such as an ast er isk, t o t he Text propert y for a v alidat or cont r ol. I n t his scenar io, t he HTML charact er appears w her e y ou hav e t he validat or cont r ol and t he err or m essage appears in t he Validat ionSum m ary cont r ol. By set t ing t he Display propert y for t he validat or cont rol t o None, y ou can cause no err or indicat or t o appear where t he validat or cont r ol is on a page. The only indicat ion of an er ror for t he validat or w ill be t he m essage in t he Validat ionSum m ar y cont r ol. I f you prefer t o have t he er r or m essage for a validat or cont r ol appear at t he cont rol and in t he Validat ionSum m ary cont rol, leav e t he Tex t pr opert y for t he validat or cont r ol em pt y. Wit h I nt er net Explorer 4 and lat er br owsers, t he validat ion cont rols v erify t he dat a on t he client w orkst at ion and at t he serv er unless you explicit ly specify ot her wise. I n cases in w hich y ou want t o send an im pr oper ly validat ed Web page t o a Web serv er, client - side v alidat ion can cause a problem . Som e validat or cont r ols m ight be on a Web page t o encourage com pliance w it h dat a ent ry form s, but y ou m ight not want t o decline a form fr om a user j ust because t hey fail t o com ply w it h all t he validat or cont rols on a Web page. This is especially t he case in e- com m erce applicat ions or any sit uat ion in w hich t he user is doing y our organizat ion a fav or by ret ur ning t he form . I n such sit uat ions, you can explicit ly disable client - side scr ipt validat ion by set t ing t he EnableClient Scr ipt pr opert y for t he validat or cont r ol t o False. One of t he gr eat feat ur es of v alidat or cont r ols is t hat t hey pr ov ide a lot of funct ionalit y w it hout any pr ogram m ing. How ev er , y ou can also pr ogram t he validat or cont rols and der iv e ev en m or e funct ionalit y from t hem . I f t he dat a for any validat or cont r ol on a page doesn’t sat isfy t he validat or, t he page’s I sValid propert y becom es False. As a consequence, y ou can use t he page’s I sValid propert y t o ex ecut e blocks of code condit ionally. I n addit ion, ASP.NET support s a Validat or Collect ion obj ect for each page. Wit h t his obj ect , y ou can it erat e t hr ough t he validat or cont r ols on a page and check each m em ber’s I sValid pr opert y . This capabilit y enables y ou t o r espond select iv ely t o er rors from indiv idual v alidat or cont r ols on a page. Usin g Va lida t or Con t r ols on W e b Pa ge s Adding validat or cont r ols t o a Web page is a sim ple m at t er of dragging t hem t o a Web page in Design v iew fr om t he Web Form s t ab of t he Toolbox . Figur e 11- 25 shows a Web page w it h t hr ee v alidat or cont r ols. The basic Web page design is an adapt at ion of t he one used in t he pr eceding sam ple. Aside fr om t he validat or cont r ols, t he m ain dist inct ion is t he om ission of t he but t on for m odify ing t ext box values. The Web page is WebForm 1.aspx in t he Validat orUI Sam ple pr oj ect . Figur e 11- 25 shows a select ed validat or cont rol next t o t he Com pany Nam e t ext box. The r ight panel in Figur e 11- 25 displays t he Propert ies window for t he select ed cont rol. The Pr opert ies w indow for t he select ed validat or cont r ol shows t he default I D nam e Requir edFieldValidat or1. The Cont rolToValidat e pr opert y reads Text Box2. You m ust always set t he Cont r olToValidat e pr opert y for a Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  17. validat or cont rol because t he sole purpose of a validat or cont rol is t o check t he validit y of anot her cont r ol. The validat or cont rol I D and Cont r olToValidat e set t ings indicat e t hat t he form isn’t valid w it hout an ent ry for t he Com pany Nam e t ext box, which is Text Box2. I nst ead of t he default err or m essage r et ur ned by t he RequiredFieldValidat or cont rol, t he Propert ies w indow shows t he set t ing “Ent er a com pany nam e” for t he Er rorMessage pr opert y. Figu re 1 1 - 2 5 . See t h e va lid a t or con t r ol in dicat or s ( * ) a n d t h e V a lid a t ion Su m m a ry con t rol in De sig n view for t h e W eb For m 1 .a spx pa g e in t h e V a lid a t orUI Sa m p le p roj ect . Turn y our at t ent ion again t o t he Design v iew of t he Web page. You can see t w o addit ional validat or cont rols next t o t he t ex t box for Phone t ext box values. One of t hese, a Requir edFieldValidat or, necessit at es a Phone t ext box ent ry, and t he ot her , a Regular ExpressionValidat or, specifies a form at for t he t elephone num ber. By using bot h of t hese v alidat or cont r ols t oget her, t he applicat ion specifies not only t hat t he user input a phone num ber but t hat he input it in a designat ed for m at . I f y ou specified a form at for t he phone num ber by using a RegularExpr essionValidat or cont r ol w it hout also designat ing a RequiredFieldValidat or , users could subm it a valid form w it hout ent er ing anyt hing in t he Phone t ext box . I specified a designat ed form at by using t he Validat edExpression pr opert y in t he Propert ies window for t he RegularExpr essionValidat or cont r ol. Click ing t he Build but t on for t his propert y opens a w indow of pr especified r egular expr essions, fr om w hich I chose U.S. Phone Num ber. The regular expr ession for t his designat ion accept s num bers in t hese t wo form at s: ( 123) 123- 1234 and 123- 1234. A Validat ionSum m ar y cont rol appears below t he but t ons on t he Web page. Because t he Text propert y set t ings for all t he v alidat or cont r ols equal * , all t he error m essages appear in t he Validat ionSum m ar y cont rol. The only indicat or of an error next t o t he cont r ol is an * at t he locat ion wher e t he validat or cont rol appears on t he page. The default form at for list ing err or m essages in a Validat ionSum m ar y cont rol is w it h bullet s. You can select from eit her of t wo ot her Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  18. prespecified form at s or program y our ow n cust om lay out for showing err or m essages in t he Validat ionSum m ary cont rol. Figur e 11- 26 shows t he validat or cont rols depict ed in Figure 11- 25 oper at ing for som e sam ple input . Not ice t hat t he Com pany Nam e t ext box is blank and t hat t he Phone t ext box has an im proper value for a phone num ber . ( I t ends in t he let t er r inst ead of a num ber.) The Validat ionSum m ary cont r ol area of t he Web page proper ly r eport s bot h er rors, and ast er isks next t o t he t ext box es furt her signal t he need t o fix t he ent ries for t he t ext box es. Figu re 1 1 - 2 6 . Err or m essa g es an d ind ica t or s from t h e W e b Form 1 .asp x pa g e in t h e V a lid at orUI Sa m p le pr oj ect b a sed on im p rope r in pu t in t h e Com pa n yN a m e a n d Ph on e t e x t boxe s. N ot e Ther e’s a second problem wit h t he Web page show n in Figur e 11- 26 besides t he fact t hat t he t ext box ent ries ar e invalid. We’ll highlight t his second issue in t he nex t sect ion when we refer back t o t he figure. Pr ogr a m m in g t h e Pa ge I sVa lid Pr ope r t y Validat or cont rols will pass a Web page t o t he browser if y ou set t he EnableClient Scr ipt pr opert y t o False, ev en if one or m ore cont rols on a page m ak e t he page invalid. The sam e act ion also t ak es place if t he client w or kst at ion Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  19. disables client - side script ing or if t he client - side script ing capabilit y for a browser is incom pat ible w it h ECMAScr ipt 1.2, a subset of Microsoft JScr ipt . Alt hough t he validat or cont rols do operat e on a Web serv er when client - side v alidat ion doesn’t t ake place, event procedur es for t he page also operat e. The operat ion of t hese ev ent procedures, such as for a pr ocedur e t o insert a new row in a t able, can ent er invalid dat a in a dat abase. Despit e t he issues highlight ed in t he pr eceding paragraph, using serv er- side validat ion is cleaner t han client - side validat ion because it doesn’t depend on t he capabilit ies of a br owser ( or even w het her client - side script ing is disabled in a browser t hat has t he capabilit y ) . However, t o t ak e advant age of serv er- side validat ion, y ou need t he Web ser ver t o be able t o det ect whet her a page has valid cont r ols and t hen condit ionally ex ecut e dat a m anipulat ion or dat a access t asks based on t he validit y of t he cont rols. N ot e I f you use ser ver- side v alidat ion wit hout m aking dat a m anipulat ion t ask s, such as inser t s and updat es, condit ional on t he v alidit y of t he cont rols on a page, y ou r un t he r isk of ent er ing invalid dat a in your dat abase. When y ou com bine server- side validat ion wit h invalid dat a, a r elat ed pr oblem em erges. The error m essages for dat a will be one row out of sy nchr ony wit h t he inv alid dat a. As a r esult , error m essages will appear on pages wit h v alid dat a, and pages wit h invalid dat a will appear wit hout err or m essages. You can use t he I sValid propert y for a Page obj ect t o det ect on a Web ser ver whet her t he page t o w hich a Page obj ect point s has any invalid cont r ols before com m it t ing an insert or an updat e t o a dat abase. I f any cont rols are inv alid, you can bypass t he code t o insert a new r ow or updat e an ex ist ing r ow w it h t he dat a from t he invalid cont r ols. WebForm 1.aspx in t he I sValidSam ple pr oj ect dem onst rat es t he synt ax for using t he I sValid propert y for a Page obj ect . The I sValidSam ple pr oj ect is ident ical t o t he Validat orUI Sam ple pr oj ect in t he preceding sect ion except for t he follow ing Visual Basic code t o im plem ent t he cm dI nsert _Click ev ent procedur e. Bot h proj ect s assign False t o t he EnableClient Scr ipt pr opert y for all validat or cont rols, w hich forces serv er- side validat ion. The Validat or UI Sam ple pr oj ect uses t he logic from t he “Dat a Manipulat ion from ASP. NET” sect ion t o im plem ent t he cm dI nsert _Click ev ent procedur e. The I sValidSam ple proj ect insert s a new row w it h t he following adapt at ion of t he code from t he Validat or UI Sam ple pr oj ect . Not ice t he use of t he Me nam e t o point t o t he cur rent page. I f any cont rol on t he page is invalid, t he I sValid pr opert y is False, and t he procedur e doesn’t invoke t he Updat e m et hod. I nst ead, t he page ret ur ns t o t he browser wit h t he err or m essage or m essages show ing. I f t he page’s I sValid propert y is True, t he procedure execut es t he Updat e m et hod and t he browser shows t he last row in t he local ASPNETShippers Dat aTable, which cont ains t he m ost r ecent ly insert ed row. Private Sub cmdInsert_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles cmdInsert.Click ’Add text box values to new row in dataset Shippers table. Dim newRow As DataRow = das1.Tables(“ASPNETShippers”).NewRow() newRow(“CompanyName”) = TextBox2.Text newRow(“Phone”) = TextBox3.Text das1.Tables(“ASPNETShippers”).Rows.Add(newRow) Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.
  20. ’Update method synchronizes inserted local row ’with its copy in northwind and returns the identity ’column value added by the northwind database. If Me.IsValid Then dap1.Update(das1, “ASPNETShippers”) ’Move to last row and populate text boxes Session(“MyRowID”) = _ das1.Tables(“ASPNETShippers”).Rows.Count - 1 MoveToRow() End If End Sub Figur es 11- 27 and 11- 28 show t he WebForm 1.aspx page from t he I sValidSam ple proj ect in operat ion. Figur e 11- 27 shows t he r esult fr om an at t em pt t o insert a new row wit h an invalid Phone field value. ( I t ends wit h t he let t er r inst ead of a num ber.) Not ice t hat t he er ror m essage at t he bot t om of t he screen and t he ast erisk highlight t he problem and inst r uct t he user w hat t o do ( fix t he er ror and reinsert ) . Also, not ice t hat t he ShipperI D t ext box is em pt y. This is because t he procedur e didn’t at t em pt t o execut e t he I nsert st at em ent w it h invalid dat a according t o t he Web page validat or cont r ols. Figure 11- 28 shows t he Web page ret ur ned by t he Web serv er aft er t he user changes t he last charact er in t he Phone t ext box fr om r t o 4. Not ice t hat t his v ersion includes a ShipperI D value, indicat ing t hat t he Web serv er subm it t ed t he new r ow t o t he SQL Serv er inst ance and receiv ed a new colum n value as an out put param et er value fr om t he st or ed procedur e t hat perform ed t he insert . Figu r e 1 1 - 2 7 . W e bFor m 1 .a sp x from t h e I sVa lidSa m ple pr oj e ct w it h an in va lid valu e in t h e Ph on e t ex t box . Please purchase PDF Split-Merge on www.verypdf.com to remove this watermark.

CÓ THỂ BẠN MUỐN DOWNLOAD

Đồng bộ tài khoản