ASP Update - Sample ASP Files - Update Motes Notes...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Sample ASP Files - Update Mote’s Notes 4/25/2011 Update1A.asp This small example allows the user to select an active employee (i.e., Active='Y') from a drop-down list, then pass their EID to the second ASP script where an UPDATE command converts the employee to a former employee (i.e., Active='N').
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Update1A.asp <html> <head> <title>Update 1A</title> <link rel=stylesheet type='text/css' href='MyStyle.css'> </head> <!--#include file="MyInfo.asp" --> <body> <% Response.Write("<h2>Update 1A: Employee Termination</h2>") ' Open connection to back-end SQL Server database Set conn=Server.CreateObject("ADODB.Connection") conn.CommandTimeout=15 conn.ConnectionTimeout=15 conn.Open BackEnd ' Begin input form Response.Write("<form action='Update1A-Step2.asp' method='post'>") ' Display employees (as drop-down list) Response.Write("<table border=0>") sql="SELECT FirstName, LastName, EID FROM tblEmployee WHERE Active='Y' ORDER BY LastName, FirstName" Set rst=Server.CreateObject("ADODB.Recordset") rst.Open sql, conn Response.Write("<tr><th align='left'>Employee</th><td align='left'>") Response.Write("<select name='EID' style='width:250px'>") Response.Write("<option value=''></option>") Do Until rst.EOF Display=rst("FirstName") & " " & rst("LastName") & " [" & rst("EID") & "]" Response.Write("<option value='" & rst("EID") & "'>" & Display & "</option>") rst.MoveNext Loop Response.Write("</select>") Response.Write("</td></tr>") rst.Close Set rst=Nothing ' Display button Response.Write("<tr><th></th><td align='left'><input type='submit' value='Update' style='width:100px'></td></tr>") Response.Write("</table>") ' End input form Response.Write("</form>") ' Close database connection conn.Close Set conn=Nothing %> </body> </html>
Background image of page 2
3 Update1A-Step2.asp <html> <head> <title>Update 1A</title> <link rel=stylesheet type='text/css' href='MyStyle.css'> </head> <!--#include file="MyInfo.asp" --> <body> <% Response.Write("<h2>Update 1A: Employee Termination</h2>") ' Fetch user input from previous page SelectedEID=Request.Form("EID") ' Open connection to back-end SQL Server database Set conn=Server.CreateObject("ADODB.Connection") conn.CommandTimeout=15 conn.ConnectionTimeout=15 conn.Open BackEnd ' Validate user input Errors=0 ErrorMessage="" ' Validation: EID (non-blank) If Len(SelectedEID)=0 Then Errors=Errors+1 ErrorMessage=ErrorMessage & "An employee must be selected.<br>" End If ' Update employee if there are no errors If Errors>0 Then ' Display error message Response.Write("<h3>ERRORS:</h3>") Response.Write("<p>" & ErrorMessage & "</p>") Else ' Define action command sql="UPDATE tblEmployee SET Active='N' WHERE EID='" & SelectedEID & "'" ' Execute action command (no recordset generated) Set ActionCommand=Server.CreateObject("ADODB.Command") Set ActionCommand.ActiveConnection=conn ActionCommand.CommandType=1 ActionCommand.CommandText=sql ActionCommand.Execute ' Release action command object Set ActionCommand=Nothing ' Display success message Response.Write("<h3>SUCCESS:</h3>") Response.Write("<p>The employee record has been marked as inactive.</p>") End If etc.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/26/2011 for the course MIS 325 taught by Professor Mote during the Spring '08 term at University of Texas at Austin.

Page1 / 11

ASP Update - Sample ASP Files - Update Motes Notes...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online