1 / 14

21 – Web applications: Databases & ASP

21 – Web applications: Databases & ASP. Session Aims & Objectives. Aims To introduce the fundamental ideas involved in using server-side code to read data from databases Objectives, by end of this week’s sessions, you should be able to:

rod
Download Presentation

21 – Web applications: Databases & ASP

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. 21 – Web applications:Databases & ASP

  2. Session Aims & Objectives • Aims • To introduce the fundamental ideas involved in using server-side code to read data from databases • Objectives,by end of this week’s sessions, you should be able to: • create an ASP web page that displays data read from a database

  3. People Database

  4. Example 1: People (html) People.asp <html> <head> <title>Personal Address Book</title> </head> <body> <p><center><b><font size=+2> Personal Address Book </font></b></center> <% ' ASP code will go here (next slide) %> </body> </html>

  5. Example 1: People (ASP) rs <html> <head><title>Personal Address Book</title></head> <body> <p><center><b><font size=+2> Personal Address Book</font></b></center> <% Const cs = "Provider=…;Data Source=D:\People.mdb; " Dim rs Set rs = CreateObject("ADODB.Recordset") rs.Open "Person", cs Do Until rs.EOF Response.Write rs.Fields("Surname").Value Response.Write "<br>" rs.MoveNext Loop rs.Close Set rs = Nothing %> </body> </html>

  6. Example 1: People (recordset 1) <html> <head><title>Personal Address Book</title></head> <body> <p><center><b><font size=+2> Personal Address Book</font></b></center> <% Const cs = "…" Dim rs Set rs = CreateObject("ADODB.Recordset") rs.Open "Person", cs Do Until rs.EOF Response.Write rs.Fields("Surname").Value Response.Write "<br>" rs.MoveNext Loop rs.Close Set rs = Nothing %> </body> </html> rs Dixon

  7. Example 1: People (recordset 2) <html> <head><title>Personal Address Book</title></head> <body> <p><center><b><font size=+2> Personal Address Book</font></b></center> <% Const cs = "…" Dim rs Set rs = CreateObject("ADODB.Recordset") rs.Open "Person", cs Do Until rs.EOF Response.Write rs.Fields("Surname").Value Response.Write "<br>" rs.MoveNext Loop rs.Close Set rs = Nothing %> </body> </html> rs Dixon Smith

  8. Example 1: People (recordset 3) <html> <head><title>Personal Address Book</title></head> <body> <p><center><b><font size=+2> Personal Address Book</font></b></center> <% Const cs = "…" Dim rs Set rs = CreateObject("ADODB.Recordset") rs.Open "Person", cs Do Until rs.EOF Response.Write rs.Fields("Surname").Value Response.Write "<br>" rs.MoveNext Loop rs.Close Set rs = Nothing %> </body> </html> rs Dixon Smith Jones

  9. Example 1: People (recordset 4) <html> <head><title>Personal Address Book</title></head> <body> <p><center><b><font size=+2> Personal Address Book</font></b></center> <% Const cs = "…" Dim rs Set rs = CreateObject("ADODB.Recordset") rs.Open "Person", cs Do Until rs.EOF Response.Write rs.Fields("Surname").Value Response.Write "<br>" rs.MoveNext Loop rs.Close Set rs = Nothing %> </body> </html> rs Dixon Smith Jones Bloggs

  10. Example 1: People (recordset 5) <html> <head><title>Personal Address Book</title></head> <body> <p><center><b><font size=+2> Personal Address Book</font></b></center> <% Const cs = "…" Dim rs Set rs = CreateObject("ADODB.Recordset") rs.Open "Person", cs Do Until rs.EOF Response.Write rs.Fields("Surname").Value Response.Write "<br>" rs.MoveNext Loop rs.Close Set rs = Nothing %> </body> </html> People.asp rs Dixon Smith Jones Bloggs Anderson

  11. Example 2: Person (html) <html> <head> <title>Person's Details</title> </head> <body> <p><center><b><font size=+2>Person's Details</font></b></center> <% ' ASP code will go here (next slide). %> <form name="frmPerson" action="Person.asp" method=post> <input name="btnPrev" type="submit" value="Previous"> <input name="btnNext" type="submit" value="Next"> </form> </body> </html> Person.asp

  12. Example 2: Person (ASP) <% Const adOpenDynamic = 3 Const cs = "…" Dim rs Set rs = CreateObject("ADODB.Recordset") rs.Open "Person", cs, adOpenDynamic If Session("curID") <> "" Then rs.Find"[ID] = " & Session("curID") If Request.Form("btnPrev") <> "" Then rs.MovePrevious ElseIf Request.Form("btnNext") <> "" Then rs.MoveNext End If End If Session("curID") = rs.Fields("ID").Value Response.Write rs.Fields("Surname").Value & "<br>" Response.Write rs.Fields("Forenames").Value rs.Close Set rs = Nothing %>

  13. SQL all fields • Structured Query Language • 4th Generation Language • code describes what (not how) • (VB 3rd Generation) • SELECT statement • used to get data • can be embedded in VB, via rs.Open:rs.Open "Person", csrs.Open "SELECT * FROM [Person]", cs

  14. SQL • WHERE clause • used to restrict data SELECT * FROM [People] WHERE [age]>=18; • ORDER BY clause • used to change order of data SELECT * FROM [People] ORDER BY [Surname];

More Related