1 / 33

Marrying HTML and Databases using Active Server Pages

Marrying HTML and Databases using Active Server Pages. JJ Cadiz. Outline. Who is this JJ guy? What can you do with ASP? How does ASP work? Hardware & Software requirements Data access using ASP Example ASP systems. Things I won’t cover. Security Visual Basic Script Java Script

larsonr
Download Presentation

Marrying HTML and Databases using Active Server Pages

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Marrying HTML and Databases using Active Server Pages JJ Cadiz

  2. Outline • Who is this JJ guy? • What can you do with ASP? • How does ASP work? • Hardware & Software requirements • Data access using ASP • Example ASP systems

  3. Things I won’t cover • Security • Visual Basic Script • Java Script • Client-side scripting • Scalability • Concurrency • Big web sites don’t use MS Access (I hope)

  4. About my background... • Masters of HCI student, class of 99 • Work full time on a CMU research team • Have used ASP heavily for past two years • data collection • experimental tools development • Joining Microsoft Research in August

  5. What can you do with ASP?

  6. Example sites • Microsoft tech support sitesupport.microsoft.com • On-line storeswww.cdw.com • On-line auction houseswww.bidnow.com

  7. ASP jobs • If you can marry databases and HTML, there are companies who want you • Search job web sites using keywords “active server pages” • careers.wsj.com • www.careerbuilder.com

  8. The Mental Model of ASP

  9. Normal HTML 1. Client requests an html page 2. Server sends client html page

  10. Dynamic HTML with ASP 1. Client requests an .asp file 2. Server processes .asp file, which generates HTML 3. Server sends generated HTML to client

  11. ASP, SQL, Databases, and HTML Web Server Database(s) VBScript & SQL ASP HTML Client Browser - Internet Explorer - Netscape Navigator

  12. Hardware & Software for ASP

  13. Server Requirements • You can’t do ASP on Andrew • ASP requires an MS Windows environment • NT Server with Internet Information Server • NT Workstation with “Peer Web Services” (10-user connection limit) • Win95/98 with Personal Web Server

  14. Developer Tools • Your favorite HTML editor • Your favorite script/code editor • A database (Access, Oracle, SQLServer) • My favorite: MS InterDev

  15. Data Access using ASP

  16. Queries in ASP: The Recordset • The mental model of a recordset • How to create and use a recordset in ASP • Example system: Employee compensation database

  17. Creating Recordsets in ASP ‘ Establish connection to database Set empCompConn = Server.CreateObject("ADODB.Connection") empCompConn.Open ”empComp” ‘empComp must be a DSN ‘ Create the SQL Command and link it to our database Set empCompCmd = Server.CreateObject("ADODB.Command") Set empCompCmd.ActiveConnection = empCompConn empCompCmd.CommandText = "SELECT * FROM Compensation" ‘ Create the recordset and link it to the command Set empCompRS = Server.CreateObject("ADODB.RecordSet") Set empCompRS.Source = empCompCmd empCompRS.LockType = adLockPessimistic empCompRS.Open … empCompRS.Close

  18. Reusing Recordset Objects empCompRS.Close empCompCmd.CommandText = "SELECT * FROM Compensation ORDER BY Salary DESC" empCompRS.Open

  19. Navigating Recordsets in ASP empCompRS.Move #rows empCompRS.MoveFirst empCompRS.MoveLast empCompRS.MoveNext empCompRS.MovePrevious empCompRS.EOF ‘ JJ’s favorite loop empCompRS.Open While(not empCompRS.EOF) DoMagic empCompRS.MoveNext Wend empCompRS.Close

  20. Accessing Fields • Moving data from the database to ASP Dim salary salary = empCompRS.Fields("salary").Value • Moving data from ASP to the database ... empCompRS.Fields("options").Value = 750 ...

  21. Creating and Editing Records • Editing existing records empCompRS.Edit ... empCompRS.Update • Creating records ‘ Doesn’t matter where the record pointer is when you do this ‘ Make sure to ensure unique keys when adding records! empCompRS.AddNew ... empCompRS.Update

  22. Creating and Editing Records • Example: For all the employees making less than $53,000/year: • Increase everyone’s salary by $5000/year • Decrease everyone’s stock options by 250/year • Add an employee who makes $54,000 and receives 100 options each year

  23. Putting it all together:Authoring ASP pages

  24. ASP File Structure • ASP commands go inside <% %> tags • Script code goes inside <SCRIPT> </SCRIPT> tags • Anything outside of these tags is HTML • Comments inside ASP or Script code are prefaced by a single quote <% ‘ Good programmers write lots of comments! %>

  25. A simple ASP file <% ' Simple ASP code that gives the appropriate greeting based on the time of day ' Get the time of day Dim currentTime currentTime = now ' Output the correct greeting based on whether it's morning, ' afternoon, or evening if(currentTime >= #5:00am#) AND (currentTime < #12:00pm#) then %> Good morning! <% elseif(currentTime >= #12:00pm#) AND (currentTime < #6:00pm#) then %> Good afternoon! <% else %> Good evening! <% end if %> The current time is <% = currentTime %>

  26. Now let’s design a system... • An on-line store • The story... • What should our product be? • How much should it cost? • Orders taken via credit card and shipped via UPS

  27. The design • Design the database • Design the HTML pages • Tell me what the ASP code needs to do

More Related