33
Marrying HTML and Databases using Active Server Pages JJ Cadiz

Marrying HTML and Databases using Active Server Pages

  • Upload
    reece

  • View
    51

  • Download
    0

Embed Size (px)

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 Presentation

Citation preview

Page 1: Marrying HTML and Databases using Active Server Pages

Marrying HTML and Databases using Active

Server PagesJJ Cadiz

Page 2: Marrying HTML and Databases using Active Server Pages

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

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
Page 5: Marrying HTML and Databases using Active Server Pages

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
Page 7: Marrying HTML and Databases using Active Server Pages

What can you do with ASP?

Page 8: Marrying HTML and Databases using Active Server Pages

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

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
Page 11: Marrying HTML and Databases using Active Server Pages

The Mental Model of ASP

Page 12: Marrying HTML and Databases using Active Server Pages

Normal HTML

1. Client requests an html page2. Server sends client html page

Page 13: Marrying HTML and Databases using Active Server Pages

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

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
Page 16: Marrying HTML and Databases using Active Server Pages

Hardware & Software for ASP

Page 17: Marrying HTML and Databases using Active Server Pages

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

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
Page 20: Marrying HTML and Databases using Active Server Pages

Data Access using ASP

Page 21: Marrying HTML and Databases using Active Server Pages

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

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

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

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

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

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

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
Page 29: Marrying HTML and Databases using Active Server Pages

Putting it all together:Authoring ASP pages

Page 30: Marrying HTML and Databases using Active Server Pages

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

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

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

The design

• Design the database• Design the HTML pages• Tell me what the ASP code needs

to do