Presentation is loading. Please wait.

Presentation is loading. Please wait.

Server Side Programming ASP1 Server Side Programming Database Integration (cont.) Internet Systems Design.

Similar presentations


Presentation on theme: "Server Side Programming ASP1 Server Side Programming Database Integration (cont.) Internet Systems Design."— Presentation transcript:

1 Server Side Programming ASP1 Server Side Programming Database Integration (cont.) Internet Systems Design

2 Server Side Programming ASP2 Overview n Review of Server Side Programming –ASP –VBScript n Advanced Database Interfacing with SQL –Insert –Delete –Update n Examples with Code

3 Server Side Programming ASP3 How can database be accessed by web browser? Web browser Server Side Programming e.g. Microsoft IIS server : ASP (VBScript, JScript, SQL) Internet Database

4 Server Side Programming ASP4 ASP Definition “Microsoft Active Server Pages (ASP) is a server-side scripting environment that you can use to create and run dynamic, interactive Web server applications. With ASP, you can combine HTML pages, script commands, and COM components to create interactive Web pages or powerful Web-based applications, which are easy to develop and modify.” - Microsoft’s Latest Definition

5 Server Side Programming ASP5 What are Active Server Pages? n Runs on IIS n Can provide compile-free application environment

6 Server Side Programming ASP6 ASP Basics n ASP file is a text file with the extension.asp n it contains any combination of: –Text –HTML Tags –ASP Script Commands/Components

7 Server Side Programming ASP7 ASP Script n ASP Script could be VBScript or Jscript (ECMAScript) n A script is a series of commands or instructions. n Script command instructs the web server to perform an action. n VBScript is similar to Visual Basic and Visual Basic for Application (VBA).

8 Server Side Programming ASP8 VBScript Basics n Not case sensitive n Declaring Variables VBScript does not require variable declarations, but it is good scripting practice to declare all variables before using them. To declare a variable in VBScript, use the Dim, Public, or Private statement.

9 Server Side Programming ASP9 VBScript Basics n VBScript Operators: –Arithmetic: +, -, *, /, ^ –Comparison: =, <>,, = –Logical (for Boolean variables): Not, And, Or, Xor

10 Server Side Programming ASP10 Running ASP n Ensure.asp extensions are enabled in IIS n Save.htm,.asp, and.mdb on server in same folder (or give full folder extensions of file locations in your code) n Client accesses the file in similar fashion to.htm (or.html) file n Server detects.asp extension and runs script within ASP tags n Results sent to client

11 Server Side Programming ASP11 Using ASP n Homework 2 review –HTML form took input from a list box and invoked the.asp file –The.asp file retrieved data from a database using VB script, SQL and displayed the results to the user n Homework 3 will expand on these concepts

12 Server Side Programming ASP12 Advanced Database Interfacing

13 Server Side Programming ASP13 Database Connectivity n When a database is tied to a web site,.ASP uses an object library called ActiveX Data Objects, or ADO –E.g. The Connection object: Set objConn = Server.CreateObject("ADODB.Connection") n Several ways to connect to a database –http://www.engineering.uiowa.edu/~ie181/Docume nts/DatabaseConnectionsFromASP.htmhttp://www.engineering.uiowa.edu/~ie181/Docume nts/DatabaseConnectionsFromASP.htm

14 Server Side Programming ASP14 Structured Query Language n SQL is a standard computer language for accessing and manipulating databases n SQL (Structured Query Language) is a syntax for executing queries. But the SQL language also includes a syntax to update, insert, and delete records. –http://www.w3schools.com/sql/sql_intro.asp

15 Server Side Programming ASP15 Structured Query Language n These query and update commands together form the Data Manipulation Language (DML) part of SQL: n SELECT - extracts data from a database table n UPDATE - updates data in a database table n DELETE - deletes data from a database table n INSERT INTO - inserts new data into a database table

16 Server Side Programming ASP16 Homework 3 n 1 st part will involve inserting, deleting, and updating records in the database used in Homework 2

17 Server Side Programming ASP17 Examples of Insert, Delete, Update Statements  "INSERT INTO Products (Candy, Price) SELECT '" & candy & "'," & price &""  "DELETE FROM Products Where Candy = '" & candy & "'"  "UPDATE Products SET Price = " & price & " WHERE Candy = '" & candy & "'"

18 Server Side Programming ASP18 Example 1: Inserting Records  See http://128.255.21.191/Example5/AddCandy.htmhttp://128.255.21.191/Example5/AddCandy.htm  Only viewable in the ALF lab  Step 1: Create an Access Database

19 Server Side Programming ASP19 Example 1: Inserting Records  Step 2: Create a.html form Candy Candy: Price: $ Delete Candy

20 Server Side Programming ASP20 Example 1: Inserting Records  Step 3: Create the.asp file <% 'strSql will be the variable used to hold the sql statement string dim strSql Set MyConn = Server.CreateObject("ADODB.Connection") MyConn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("Candy.mdb") 'grab the values from the form candy = Request.form("txtCandy") price = Request.Form("txtPrice") 'create the SQL statement that will insert the data to the table 'remember text values need single quotes wrapped around them strSql = "INSERT INTO Products (Candy, Price) SELECT '" & candy & "'," & price &"" MyConn.Execute strSql Response.Write "Added the candy with the sql statement: " & strSql Set MyConn = nothing %>

21 Server Side Programming ASP21 Example 1: Inserting Records  Step 4: Save the files to a folder in the wwwroot folder, run the example and view changes…notice Licorice was added to the Products table

22 Server Side Programming ASP22 Example 2: Deleting Records  http://128.255.21.191/Example5/deleteCandy.htm http://128.255.21.191/Example5/deleteCandy.htm  Step 1: Create a.html form Candy Candy: Add Candy

23 Server Side Programming ASP23 Example 2: Deleting Records  Step 2: Create the.asp file <% 'strSql will be the variable used to hold the sql statement string dim strSql Set MyConn = Server.CreateObject("ADODB.Connection") MyConn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("Candy.mdb") 'grab the candy name from the form candy = Request.form("txtCandy") 'create the SQL statement that will insert the data to the table 'remember text values need single quotes to wrapped around them strSql = "Delete FROM Products Where Candy = '" & candy & "'" MyConn.Execute strSql Response.Write "Deleted the candy with the sql statement: " & strSql Set MyConn = nothing %> Add Candy - Update Candy - Delete Candy

24 Server Side Programming ASP24 Example 2: Deleting Records  Step 3: Save the files to a folder in the wwwroot folder, run the example and view changes…notice Licorice was deleted from the Products table

25 Server Side Programming ASP25 Example 3: Updating Records  http://128.255.21.191/Example5/updateCandy.htm http://128.255.21.191/Example5/updateCandy.htm  Step 1: Create a.html form Candy Gum Suckers Taffy Skittles M&Ms Lifesavers Snickers New Price:

26 Server Side Programming ASP26 Example 3: Updating Records  Step 2: Create the.asp file <% 'strSql will be the variable used to hold the sql statement string dim strSql Set MyConn = Server.CreateObject("ADODB.Connection") MyConn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("Candy.mdb") 'grab the candy name from the form candy = Request.form("selCandy") price = Request.form("txtPrice") 'create the SQL statement that will insert the data to the table 'remember text values need single quotes to wrapped around them strSql = "UPDATE Products SET Price = " & price & " WHERE Candy = '" & candy & "'" MyConn.Execute strSql Response.Write "Update the candy price with the sql statement: " & strSql Set MyConn = nothing %>

27 Server Side Programming ASP27 Example 3: Updating Records  Step 3: Save the files to a folder in the wwwroot folder, run the example and view changes…notice Snicker’s price was changed from $4.00 to $0.25 in the Products table


Download ppt "Server Side Programming ASP1 Server Side Programming Database Integration (cont.) Internet Systems Design."

Similar presentations


Ads by Google