Mark Dixon Page 1 20 – Web applications: Writing data to Databases using ASP.

Slides:



Advertisements
Similar presentations
Mark Dixon Page 1 23 – Object Oriented Programming in PhP.
Advertisements

Mark Dixon Page 1 16 – Passing Data between pages: Forms, Sessions, & Query Strings.
Mark Dixon Page 1 05 – Database Design: Sub-forms.
Mark Dixon, SoCCE SOFT 131Page 1 16 – Persistent data storage: relational databases and ADO.
Mark Dixon Page 1 17 – Persistent data storage: relational databases and ADO.
Mark Dixon, SoCCE SOFT 131Page 1 24 – Web applications: Writing data to Databases using ASP.
Mark Dixon, SoCCE SOFT 131Page 1 23 – Modular Design in ASP.
XP New Perspectives on Microsoft Office Access 2003, Second Edition- Tutorial 2 1 Microsoft Office Access 2003 Tutorial 2 – Creating And Maintaining A.
Mark Dixon Page 1 02 – Dynamic HTML (client-side scripting)
Access Tutorial 1 Creating a Database
Mark Dixon Page 1 21 – Object Oriented Programming in ASP.
Mark Dixon, SoCCE SOFT 131Page 1 23 – Entity-relationship diagrams.
Mark Dixon, SoCCE SOFT 131Page 1 22 – Web applications: Writing data to Databases using ASP.
Mark Dixon Page 1 18 – Persistent data storage: relational databases and ADO.
Mark Dixon Page 1 02 – Queries: Query by Example.
Mark Dixon Page 1 20 – Modular Design in ASP. Mark Dixon Page 2 Session Aims & Objectives Aims –Highlight modular design techniques in ASP Objectives,
Creating And Maintaining A Database. 2 Learn the guidelines for designing databases When designing a database, first try to think of all the fields of.
Mark Dixon, SoCCE SOFT 131Page 1 18 – Structured Query Language.
Master Detail Page Set Enabling Users to See More Detailed Data.
Mark Dixon, SoCCE SOFT 131Page 1 19 – Web applications: Server-side code (ASP)
Mark Dixon, SoCCE SOFT 131Page 1 20 – Web applications: Writing data to Databases using ASP.
COMPREHENSIVE Excel Tutorial 8 Developing an Excel Application.
®® Microsoft Windows 7 Windows Tutorial 6 Searching for Information and Collaborating with Others.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
ACCESS CHAPTER 1. OBJECTIVES Tables Queries Forms Reports Primary and Foreign Keys Relationship.
Mark Dixon 1 20 – Persistent data storage: relational databases and ADO.
Mark Dixon Page 1 5 – Persistent data storage: relational databases.
Tutorial 10 Adding Spry Elements and Database Functionality Dreamweaver CS3 Tutorial 101.
Mark Dixon Page 1 23 – Web applications: Writing data to Databases using PhP.
Mark Dixon Page 1 24 – Object Oriented Programming in ASP.
Mark Dixon Page 1 3 – Web applications: Server-side code (JSP)
Mark Dixon 1 22 – Web applications: Writing data to Databases using ASP.Net.
Mark Dixon Page 1 23 – Web applications: Writing data to Databases using ASP.
® Microsoft Access 2010 Tutorial 1 Creating a Database.
® Microsoft Office 2010 Access Tutorial 2 Building a Database and Defining Table Relationships.
Office 2003 Advanced Concepts and Techniques M i c r o s o f t Access Project 6 Switchboards, PivotTables, and PivotCharts.
Mark Dixon Page 1 21 – Persistent data storage: relational databases and MySQL.
XP New Perspectives on Microsoft Access 2002 Tutorial 21 Microsoft Access Tutorial 2 – Creating And Maintaining A Database.
XP New Perspectives on Microsoft Office Access 2003, Second Edition- Tutorial 2 1 Microsoft Office Access 2003 Tutorial 2 – Creating And Maintaining A.
Lecture Note 10: Simple Database Techniques. Introduction –Database System –Access, SQL Server and others. –Microsoft Access - Interacting with this databases.
® Microsoft Office 2013 Access Creating a Database.
Mark Dixon Page 1 21 – Web applications: Writing data to Databases using ASP.
COMPREHENSIVE Access Tutorial 12 Managing and Securing a Database.
® Microsoft Access 2010 Tutorial 12 Managing and Securing a Database.
Course ILT Forms and queries Unit objectives Create forms by using AutoForm and the Form Wizard, and add or modify form headers and footers Open and enter.
Mark Dixon 1 21 – Databases: Multiple Tables and Writing Data.
Paging Through a Data Table Creating a Navigation Bar Using the Recordset Navigation Bar Server Behavior.
Microsoft Access 2013 ®® Tutorial 12 Managing and Securing a Database.
3 Copyright © 2004, Oracle. All rights reserved. Working in the Forms Developer Environment.
XP New Perspectives on Microsoft Office FrontPage 2003 Tutorial 7 1 Microsoft Office FrontPage 2003 Tutorial 8 – Integrating a Database with a FrontPage.
Microsoft FrontPage 2003 Illustrated Complete Integrating a Database with a Web Site.
Mark Dixon, SoCCE SOFT 131Page 1 23 – Web applications: Databases & ASP.
INTRODUCTION TO ACCESS. OBJECTIVES  Define the terms field, record, table, relational database, primary key, and foreign key  Create a blank database.
Introduction to KE EMu Unit objectives: Introduction to Windows Use the keyboard and mouse Use the desktop Open, move and resize a.
Mark Dixon 1 22 – Object Oriented Programming. Mark Dixon 2 Questions: Databases How many primary keys? How many foreign keys? 3 2.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Introduction to KE EMu Unit objectives: Introduction to Windows Use the keyboard and mouse Use the desktop Open, move and resize a.
Designing a Relational Database 13.4 Page A database should be created based on a design  Three steps Determine what information should be stored.
Mark Dixon, SoCCE SOFT 131Page 1 12 – Databases: Structured Query Language.
Microsoft Office 2013 Try It! Chapter 4 Storing Data in Access.
XP New Perspectives on Microsoft Office Access 2003, Second Edition- Tutorial 8 1 Microsoft Office Access 2003 Tutorial 8 – Integrating Access with the.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 6: Accessing a database with PHP Rob Gleasure robgleasure.com.
® Microsoft Access 2010 Tutorial 9 Using Action Queries and Advanced Table Relationships.
XP New Perspectives on Creating Web Pages With Word Tutorial 1 1 Creating Web Pages With Word Tutorial 1.
18 – Databases: Structured Query Language
23 – Object Oriented Programming in ASP
Setting the Permissions
17 – Persistent data storage: relational databases and ADO
Presentation transcript:

Mark Dixon Page 1 20 – Web applications: Writing data to Databases using ASP

Mark Dixon Page 2 Questions: HTML in VB Are these correct (assume variables and fields exist)? f = f + rs.Fields("Description").value h = h + rs.Fields(" Name").value a = " " + a " " html = html + h = " " + h + " "   

Mark Dixon Page 3 Questions: Databases How many primary keys? How many foreign keys? 3 2

Mark Dixon Page 4 Session Aims & Objectives Aims –To introduce the fundamental ideas involved in using server-side code to write data to databases Objectives, by end of this week’s sessions, you should be able to: –create an ASP web page that allows the user to store data in database

Mark Dixon Page 5 Searching for Data Recordset methods –Find: searches for the next record to match given criteria string: e.g. "Name = 'Smith' " ( " are for VB string) ( ' are for database string)

Mark Dixon Page 6 Example: Person v1 (Specification) User requirement: –Display person’s details from database online, and be able to move to next and previous person (record) Problem: –record set does not persist between pages –Difficult to use.MoveNext and.MovePrev recordset methods:

Mark Dixon Page 7 Example: Person v1 Sub Page_Load() Const cs = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\People.mdb;" Dim rs As Object Dim s As String Dim id As String rs = CreateObject("ADODB.Recordset") rs.Open("Person", cs, 3) id = CStr(Session("curID")) If id > "" Then rs.Find("[ID] = " + id) If Request.Form("btnPrev") > "" Then rs.MovePrevious() ElseIf Request.Form("btnNext") > "" Then rs.MoveNext() End If Session("curID") = rs.Fields("ID").Value s = rs.Fields("Surname").Value + " " parData.InnerHtml = s rs.Close() rs = Nothing End Sub Use session variable to record current position in db Find last position in db (using id from session variable)

Mark Dixon Page 8 Example: Person v2 (Specification) User requirement: Display person’s details from database online, and be able to move to next and previous person (record) –Change surname and save to database

Mark Dixon Page 9 Database Permissions 1 Windows Explorer –Tools –Folder Options –View Tab Need to turn 'simple file sharing' off (as this disables the security tab in file properties)

Mark Dixon Page 10 Database Permissions 2 In order for ASP to write to a database –Need to give write access to Internet Guest Account for database file (People.mdb) Right-click on file in Windows Explorer (the following screens are for Windows XP)

Mark Dixon Page 11 Database Permissions 3 Click Security tab Click Add button

Mark Dixon Page 12 Database Permissions 4 Click Advanced button

Mark Dixon Page 13 Select Internet Guest Account IUSR_ … Click Find button Click user Click OK button Database Permissions 5

Mark Dixon Page 14 Database Permissions 6 Select Internet Guest Account Ensure write access is on Repeat for ASPNET account

Mark Dixon Page 15 Changing Data Recordset methods –AddNew: inserts a new record and makes it current –rd.Fields("FieldName").value = "Data" –Update: sends changes back to DB –Delete: deletes currently selected record

Mark Dixon Page 16 Writing data to a database create recordset open recordset –dynamic cursor (3), pessimistic locking (3) to add a record –use to AddNew method rs.AddNew to delete a record –use the Delete method rs.Delete to change existing data –assign a new value to fields rs.Fields("Surname").Value = "Fred"

Mark Dixon Page 17 Example: Person v2 Sub Page_Load() Const cs = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\People.mdb;" Dim rs As Object Dim id As String rs = CreateObject("ADODB.Recordset") rs.Open("Person", cs, 3, 3) id = CStr(Session("curID")) If id > "" Then rs.Find("[ID] = " + id) If Request.Form("btnPrev") > "" Then rs.MovePrevious() ElseIf Request.Form("btnNext") > "" Then rs.MoveNext() ElseIf Request.Form("btnSave") > "" Then rs.Fields("Surname").Value = txtSurname.Value rs.Update() End If Session("curID") = rs.Fields("ID").Value txtSurname.Value = rs.Fields("Surname").Value rs.Close() rs = Nothing End Sub

Mark Dixon Page 18 Example: Person v3

Mark Dixon Page 19 Tutorial Exercise: Person v1 LEARNING OBJECTIVE: use session variable to store id practice problem solving skills Task 1: Get the Person (v1) example from the lecture working. Task 2: Modify your code, so that all fields are displayed (use a table). Task 3: Modify your code, so that it does not generate an error when the user goes past the end or beginning of the recordset. Hint: You can't stop it 'falling off' the end of the recordset. But you can detect it using EOF and move back.

Mark Dixon Page 20 Tutorial Exercise: Person v2 & v3 Task 1: Get the Person (v2) example from the lecture working. Task 2: Modify your code, so that a line of text is displayed confirming that data has been saved. Task 3: Modify your code, so that an add button is included, which allows a new record to be added. Task 4: Modify your code, so that a delete button is included, which allows the current record to be deleted.