marrying html and databases using active server pages
DESCRIPTION
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 - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Marrying HTML and Databases using Active Server Pages](https://reader035.vdocuments.site/reader035/viewer/2022062809/5681599e550346895dc6e94e/html5/thumbnails/1.jpg)
Marrying HTML and Databases using Active
Server PagesJJ Cadiz
![Page 2: Marrying HTML and Databases using Active Server Pages](https://reader035.vdocuments.site/reader035/viewer/2022062809/5681599e550346895dc6e94e/html5/thumbnails/2.jpg)
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
![Page 3: Marrying HTML and Databases using Active Server Pages](https://reader035.vdocuments.site/reader035/viewer/2022062809/5681599e550346895dc6e94e/html5/thumbnails/3.jpg)
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)
![Page 4: Marrying HTML and Databases using Active Server Pages](https://reader035.vdocuments.site/reader035/viewer/2022062809/5681599e550346895dc6e94e/html5/thumbnails/4.jpg)
![Page 5: Marrying HTML and Databases using Active Server Pages](https://reader035.vdocuments.site/reader035/viewer/2022062809/5681599e550346895dc6e94e/html5/thumbnails/5.jpg)
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
![Page 6: Marrying HTML and Databases using Active Server Pages](https://reader035.vdocuments.site/reader035/viewer/2022062809/5681599e550346895dc6e94e/html5/thumbnails/6.jpg)
![Page 7: Marrying HTML and Databases using Active Server Pages](https://reader035.vdocuments.site/reader035/viewer/2022062809/5681599e550346895dc6e94e/html5/thumbnails/7.jpg)
What can you do with ASP?
![Page 8: Marrying HTML and Databases using Active Server Pages](https://reader035.vdocuments.site/reader035/viewer/2022062809/5681599e550346895dc6e94e/html5/thumbnails/8.jpg)
Example sites
• Microsoft tech support sitesupport.microsoft.com
• On-line storeswww.cdw.com
• On-line auction houseswww.bidnow.com
![Page 9: Marrying HTML and Databases using Active Server Pages](https://reader035.vdocuments.site/reader035/viewer/2022062809/5681599e550346895dc6e94e/html5/thumbnails/9.jpg)
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
![Page 10: Marrying HTML and Databases using Active Server Pages](https://reader035.vdocuments.site/reader035/viewer/2022062809/5681599e550346895dc6e94e/html5/thumbnails/10.jpg)
![Page 11: Marrying HTML and Databases using Active Server Pages](https://reader035.vdocuments.site/reader035/viewer/2022062809/5681599e550346895dc6e94e/html5/thumbnails/11.jpg)
The Mental Model of ASP
![Page 12: Marrying HTML and Databases using Active Server Pages](https://reader035.vdocuments.site/reader035/viewer/2022062809/5681599e550346895dc6e94e/html5/thumbnails/12.jpg)
Normal HTML
1. Client requests an html page2. Server sends client html page
![Page 13: Marrying HTML and Databases using Active Server Pages](https://reader035.vdocuments.site/reader035/viewer/2022062809/5681599e550346895dc6e94e/html5/thumbnails/13.jpg)
Dynamic HTML with ASP
1. Client requests an .asp file2. Server processes .asp file, which
generates HTML3. Server sends generated HTML to
client
![Page 14: Marrying HTML and Databases using Active Server Pages](https://reader035.vdocuments.site/reader035/viewer/2022062809/5681599e550346895dc6e94e/html5/thumbnails/14.jpg)
ASP, SQL, Databases, and HTML
Web Server
Client Browser- Internet Explorer
- Netscape Navigator
Database(s)
HTML
ASPVBScript & SQL
![Page 15: Marrying HTML and Databases using Active Server Pages](https://reader035.vdocuments.site/reader035/viewer/2022062809/5681599e550346895dc6e94e/html5/thumbnails/15.jpg)
![Page 16: Marrying HTML and Databases using Active Server Pages](https://reader035.vdocuments.site/reader035/viewer/2022062809/5681599e550346895dc6e94e/html5/thumbnails/16.jpg)
Hardware & Software for ASP
![Page 17: Marrying HTML and Databases using Active Server Pages](https://reader035.vdocuments.site/reader035/viewer/2022062809/5681599e550346895dc6e94e/html5/thumbnails/17.jpg)
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
![Page 18: Marrying HTML and Databases using Active Server Pages](https://reader035.vdocuments.site/reader035/viewer/2022062809/5681599e550346895dc6e94e/html5/thumbnails/18.jpg)
Developer Tools
• Your favorite HTML editor• Your favorite script/code editor• A database (Access, Oracle,
SQLServer)• My favorite: MS InterDev
![Page 19: Marrying HTML and Databases using Active Server Pages](https://reader035.vdocuments.site/reader035/viewer/2022062809/5681599e550346895dc6e94e/html5/thumbnails/19.jpg)
![Page 20: Marrying HTML and Databases using Active Server Pages](https://reader035.vdocuments.site/reader035/viewer/2022062809/5681599e550346895dc6e94e/html5/thumbnails/20.jpg)
Data Access using ASP
![Page 21: Marrying HTML and Databases using Active Server Pages](https://reader035.vdocuments.site/reader035/viewer/2022062809/5681599e550346895dc6e94e/html5/thumbnails/21.jpg)
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
![Page 22: Marrying HTML and Databases using Active Server Pages](https://reader035.vdocuments.site/reader035/viewer/2022062809/5681599e550346895dc6e94e/html5/thumbnails/22.jpg)
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
![Page 23: Marrying HTML and Databases using Active Server Pages](https://reader035.vdocuments.site/reader035/viewer/2022062809/5681599e550346895dc6e94e/html5/thumbnails/23.jpg)
Reusing Recordset ObjectsempCompRS.Close
empCompCmd.CommandText = "SELECT * FROM Compensation ORDER BY Salary DESC"
empCompRS.Open
![Page 24: Marrying HTML and Databases using Active Server Pages](https://reader035.vdocuments.site/reader035/viewer/2022062809/5681599e550346895dc6e94e/html5/thumbnails/24.jpg)
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
![Page 25: Marrying HTML and Databases using Active Server Pages](https://reader035.vdocuments.site/reader035/viewer/2022062809/5681599e550346895dc6e94e/html5/thumbnails/25.jpg)
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
...
![Page 26: Marrying HTML and Databases using Active Server Pages](https://reader035.vdocuments.site/reader035/viewer/2022062809/5681599e550346895dc6e94e/html5/thumbnails/26.jpg)
Creating and Editing Records
• Editing existing recordsempCompRS.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
![Page 27: Marrying HTML and Databases using Active Server Pages](https://reader035.vdocuments.site/reader035/viewer/2022062809/5681599e550346895dc6e94e/html5/thumbnails/27.jpg)
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
![Page 28: Marrying HTML and Databases using Active Server Pages](https://reader035.vdocuments.site/reader035/viewer/2022062809/5681599e550346895dc6e94e/html5/thumbnails/28.jpg)
![Page 29: Marrying HTML and Databases using Active Server Pages](https://reader035.vdocuments.site/reader035/viewer/2022062809/5681599e550346895dc6e94e/html5/thumbnails/29.jpg)
Putting it all together:Authoring ASP pages
![Page 30: Marrying HTML and Databases using Active Server Pages](https://reader035.vdocuments.site/reader035/viewer/2022062809/5681599e550346895dc6e94e/html5/thumbnails/30.jpg)
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!
%>
![Page 31: Marrying HTML and Databases using Active Server Pages](https://reader035.vdocuments.site/reader035/viewer/2022062809/5681599e550346895dc6e94e/html5/thumbnails/31.jpg)
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 %>
![Page 32: Marrying HTML and Databases using Active Server Pages](https://reader035.vdocuments.site/reader035/viewer/2022062809/5681599e550346895dc6e94e/html5/thumbnails/32.jpg)
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
![Page 33: Marrying HTML and Databases using Active Server Pages](https://reader035.vdocuments.site/reader035/viewer/2022062809/5681599e550346895dc6e94e/html5/thumbnails/33.jpg)
The design
• Design the database• Design the HTML pages• Tell me what the ASP code needs
to do