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

Slides:



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

CIS 375—Web App Dev II ADO I. 2 Introduction ADO (________ Data Objects) is a Microsoft technology for accessing data in a database. ADO is automatically.
Mark Dixon Page 1 16 – Passing Data between pages: Forms, Sessions, & Query Strings.
Mark Dixon Page 1 05 – Database Design: Sub-forms.
Mark Dixon Page 1 04 – Database Design: Forms. Mark Dixon Page 2 Session Aims & Objectives Aims –To allow easier data entry using forms Objectives, by.
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.
Session 6 Server-side programming - ASP. An ASP page is an HTML page interspersed with server-side code. The.ASP extension instead of.HTM denotes server-side.
Integrating Access with the Web and with Other Programs.
XP New Perspectives on Microsoft Office Access 2003, Second Edition- Tutorial 2 1 Microsoft Office Access 2003 Tutorial 2 – Creating And Maintaining A.
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,
Mark Dixon, SoCCE SOFT 131Page 1 18 – Structured Query Language.
Mark Dixon Page 1 20 – Web applications: Writing data to Databases using ASP.
Master Detail Page Set Enabling Users to See More Detailed Data.
Mark Dixon, SoCCE SOFT 131Page 1 20 – Web applications: Writing data to Databases using ASP.
Access Tutorial 8 Sharing, Integrating, and Analyzing Data
Tutorial 1 Creating a Database. Objectives Learn basic database concepts and terms Learn basic database concepts and terms Explore the Microsoft Access.
Michael Tucker DBA / Webmaster Forsyth County Public Library.
®® 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.
Mark Dixon 1 20 – Persistent data storage: relational databases and ADO.
Mark Dixon Page 1 5 – Persistent data storage: relational databases.
Copyright © 2001 by Wiley. All rights reserved. Chapter 10: Advanced Database Operations Revising Vintage Videos Setting RecordSource at run time DBGrid.
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 1 22 – Web applications: Writing data to Databases using ASP.Net.
1 Data Bound Controls II Chapter Objectives You will be able to Use a Data Source control to get data from a SQL database and make it available.
® 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 Office Access 2003, Second Edition- Tutorial 2 1 Microsoft Office Access 2003 Tutorial 2 – Creating And Maintaining A.
Mark Dixon 1 03 – Passing Data between pages: Forms, Sessions, & Query Strings.
Lecture Note 10: Simple Database Techniques. Introduction –Database System –Access, SQL Server and others. –Microsoft Access - Interacting with this databases.
XP 1 New Perspectives on XML Binding XML Data with Internet Explorer.
® Microsoft Office 2013 Access Creating a Database.
Tutorial 9 Using Action Queries and Advanced Table Relationships.
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.
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.
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.
Database Connectivity What is ADO. What is ADO? ADO is a Microsoft technology ADO stands for ActiveX Data Objects ADO is a Microsoft Active-X component.
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.
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.
COMPREHENSIVE Access Tutorial 1 Creating a Database.
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 23 – 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 Example: Person v1 (Specification) User requirement: –Display people's details from database online –need 2 pages: smith jones dixon list of people jones sally person's details

Mark Dixon Page 6 Example: PeopleList.aspx 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 rs = CreateObject("ADODB.Recordset") rs.Open("Person", cs) s = "" Do Until rs.EOF() s = s & rs.Fields("Surname").Value & " " rs.MoveNext() Loop parData.InnerHtml = s rs.Close() rs = Nothing End Sub

Mark Dixon Page 7 Example: PeopleList.aspx v2 Sub Page_Load() Const cs = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\People.mdb;" Dim rs As Object Dim s As String rs = CreateObject("ADODB.Recordset") rs.Open("Person", cs) s = "" Do Until rs.EOF() s = s & " " s = s & rs.Fields("Surname").Value & " " rs.MoveNext() Loop parData.InnerHtml = s rs.Close() rs = Nothing End Sub now links

Mark Dixon Page 8 Example: Person.aspx v2 Sub Page_Load() Const cs = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\People.mdb;" Dim sql As String Dim rs As Object Dim s As String sql = "SELECT * FROM Person WHERE id=" & Request.QueryString("id") rs = CreateObject("ADODB.Recordset") rs.Open(sql, cs) s = "" If Not rs.EOF() Then txtSurname.Value = rs.Fields("Surname").Value End If rs.Close() rs = Nothing End Sub Back to People List Surname: reads querystring (from previous page) displays data for selected record only

Mark Dixon Page 9 Example: Person v2 (Specification) User requirement: Display person’s details from database online –Change surname and save to database

Mark Dixon Page 10 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 11 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 12 Database Permissions 3 Click Security tab Click Add button

Mark Dixon Page 13 Database Permissions 4 Click Advanced button

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

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

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

Mark Dixon Page 17 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 18 Example: Person.aspx v3 Sub Page_Load() Const cs = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\People.mdb;" Dim sql As String Dim rs As Object Dim s As String sql = "SELECT * FROM Person WHERE id=" & Request.QueryString("id") rs = CreateObject("ADODB.Recordset") rs.Open(sql, cs, 3, 3 ) s = "" If Not rs.EOF() Then If Request.Form("btnSave") > "" Then rs.Fields("Surname").Value = txtSurname.Value rs.Update() End If txtSurname.Value = rs.Fields("Surname").Value End If rs.Close() rs = Nothing End Sub Back to People List Surname: Save button works now

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