MSSQL ASP MSSQL ASP ClientServer Relationship HTML Basics
MSSQL & ASP
MSSQL & ASP • Client-Server Relationship • HTML Basics • Scripting Basics • Examples
Client-Server Relationship Client – user of an application – Sends requests to the server for a specific tasks (process data, obtain data, etc) – Uses HTML to tell web browser how to display data
Client-Server Relationship Server – more specifically, ASP (Active Server Pages) – Receives requests from the client to perform a certain task – Processes data and sends results back to the client – Uses scripting languages to process data (VBScript, PHP, Java. Script)
HTML Basics HTML performs two essential tasks 1. Displays data 2. Submits data to be process
HTML Basics Tags – HTML uses tags to format data – Tag Format: <command attribute 1=“” attribute 2=“”…> Some text here (optional) </command> – Save in a text editor (or web editor like Dreamweaver) and open with IE, Netscape, etc.
HTML Basics Example: <html> <body> <p>This is a paragraph. </p> <p>Paragraph elements are defined by the p tag. </p> </body> </html>
HTML Basics Common tags – <html> - starts all documents – <body> - all text is placed here – <a> - links to other pages. Example: <a href="http: //www. w 3 schools. com/">This is a Link</a> – <table>, <td>, <tr> - formats data in table form – <form> - allow the user to enter information (explained in next slide) – Other tags - http: //www. w 3 schools. com/html_reference. asp
HTML Basics Forms - A form is defined with <form> tag Structure: <form> <input> </form>
HTML Basics Form Example: <form name="input" action="html_form_action. asp" method=“post"> Username: <input type="text" name="user"> <input type="submit" value="Submit"> </form> – When user selects the “submit” button, the information in the form is submitted to the page “html_form_action. asp”. Other form elements: http: //www. w 3 schools. com/html_forms. asp
VB Script Basics VB Scripts – Lightweight version of Visual Basic programming language – Can be placed anywhere in html code – Run by server and sent back to client – <% denotes beginning of the script – %> denotes end of script – Files with. asp extension will hold scripts (usually)
VB Script Basics Example Script: (saved as “example 1. asp”) <html> <body> <% dim name="John Harney" Response. write("My name is: <b>" & name & “</b>”) %> </body> </html> – Dim – dimensions a variable (can be any type) – Response. write – writes html content to the html page – Response Examples: – http: //www. w 3 schools. com/asp_ref _response. asp
VB Script Basics Example Form: (saved as “example 2. html”) <html> <body> <form name="input" action="example 2. asp" method="post"> Grade: <input type="text" SIZE="3" name="grade"> <input type="submit" value="Submit"> </form> </body> </html> – Form is “posted” to “example 2. asp” with the text information “grade” when the user clicks submit
VB Script Basics Example Form: (saved as “example 2. asp”) <html> <body> <% Dim grade entry = Request. Form("grade") If entry > 90 Then Response. write "<h 3>You have an A</h 3>" elseif entry > 80 Then Response. write "<h 3>You have a B</h 3>" elseif entry > 70 Then Response. wrtie "<h 3>You have a C</h 3>" else Response. write "<h 3>You have an F</h 3>" End If %> </body> </html> – Request. Form is the “posted” information from the form in “example 2. html” – “grade” is the name of the text that was submitted
ASP – Combines html and scripting with a database – Accesses the database and uses the information in data processing
ASP – commands for accessing database <% set adocon = server. Create. Object("ADODB. Connection") set adorec = server. Create. Object("ADODB. recordset") adocon. Open("dsn=cscmssql 1; uid=username; pwd=password; ") adorec. Active. Connection=adocon %> After connection is made, enter the sql command use it: <% sql. Text = “select * from database” Adocon. Open sql. Text %>
ASP Example – Sporting Goods Retailer – Contains the following 3 tables: Product (prod. ID, name, quantity, cost) Customer (cust. ID, name, card. No) Cp (cust. ID, prod. ID)
References www. w 3 schools. com – HTML, VB, ASP www. learnasp. com – ASP validation and cookies www. uncg. edu/mat/Database. Projects Mathematical Science Database Page Email: jfharney@uncg. edu Office: Bryan 384 (W F 1 -5)
- Slides: 18