ASP ScriptingJava ScriptingCGI ScriptingHTMLJavaLanguage CERP Education Links

ASP SCRIPTING

Form Transaction

' *************************************************************'    
tt1.asp
'  *************************************************************

<%@ Language=VBScript %> 
<% Option Explicit %> 
<%
Dim conn 
Dim SQL 
Dim R
Dim aConnectionString
aConnectionString = "Provider=SQLOLEDB;Data " & "Source=(local);Database=ClassRecords;" & "UID=sa;PWD=;"
Set conn = Server.Create0bject("ADODB.Connection") 
conn.Mode = adModeRead
conn.ConnectionString = aConnectionString 
conn.CursorLocation = aduseclient 
conn.Open
SQL = "SELECT * FROM Students ORDER BY LastName, FirstName" 
Set R = Server.Create0bject("ADODB.Recordset") 
R.CursorLocation = aduseclient
Call R.Open(SQL, conn, adOpenStatic, adLockReadOnly, adcmdtext)
Set R.ActiveConnection = Nothing 
conn.Close
Set conn = Nothing 
%>
<html> 
<head> 
</head> 
<body> 
<form name="frmSelectStudent" method="post" action="tt2.asp"> 
<table align="center" width="80%" border="1"> 
<tr>
<td colspan="2">
Select a student from the list, then click the Details button to view and edit that student's information.
</td> 
</tr>
<td valign="top" width="60%"> 
<select name="StudentID"> 
<%
While Not R.EOF
Response.Write "<option value=' " & R("StudentID").Value & "'>" & _ R("LastName").Value & ", " & R("Firstname").Value & "</option>" R.movenext
Wend 
R.Close 
Set R = Nothing 
%>
</select> 
</td>
<td valign="top">
<input type="Submit" value="Details" name="Details">
</td> 
</tr>
</table> 
</form> 
</body> 
</html> 

'  *************************************************************'
 tt2.asp
'  *************************************************************

<%@ Language=VBScript %> 
<% Option Explicit %>
<% Response.Buffer=True %> 
<%
Dim oStudent 
Dim StudentID 
Dim LastName 
Dim FirstName 
Dim Grade
Dim conn 
Dim SQL 
Dim R
Dim aConnectionString
StudentID = Request("StudentID") 
If StudentID = "" Then 
Response.redirect "tt1.asp" 
End If
aConnectionString = "Provider=SQLOLEDB;Data " ; & "Source=(local);Database=ClassRecords " & "UID=sa;PWD=;"
Set conn = Server.Create0bject("ADODB.Connection") 
conn.Mode = adModeRead
conn.ConnectionString = aConnectionString 
conn.CursorLocation = adUseClient
conn.open SQL = "SELECT * FROM Students WHERE StudentID=" & _ StudentID 
Set R = conn.execute(SQL, , adcmdtext)
LastName = R("LastName").Value 
FirstName = R("FirstName").Value 
Grade = R("Grade").Value 
conn.Close
Set conn = Nothing 
%>
<html> 
<head> 
</head> 
<body> 
<form name="frmSelectStudent" method="post" action="ch20iS.asp"> <input type="hidden" name="StudentID" value="<%=StudentID%>"> <table align=center width="60%">
<tr>
<td width="30%"> 
<b>Last Name</b>:
</td>
<td width="*">
<input type="text" name="LastName" value="<%=LastName%>"> 
</td>
</tr> 
<tr> 
<td width="30%">
<b>First Name</b>:
</td>
<td width="*">
<input type="text" name="FirstName" value="<%=FirstName%>"> 
</td>
</tr> 
<tr> 
<td width="30%">
<b>Grade</b>: 
</td>
<td width="*">
<input type="text" name="Grade" value="%=Grade%>"> 
</td>
</tr>
<tr> 
<td colspan="2">
<input type="Submit" name "Submit" value="Submit"> 
</td>
</tr> 
</table> 
</form> 
</body> 
</html>

'  *************************************************************
'  tt3.asp
'  *************************************************************
<%@ Language=VBScript @TRANSACTION=REQUIRED%> 
Dim oStudent 
Dim StudentID 
Dim LastName 
Dim FirstName 
Dim Grade
Sub onTransactionCommit()
Response.Write "The record has been updated.<br>"
Response.Write "Click <a href='tt1.asp'>here
</a> to return to the list."
Response.end 
End Sub
Sub onTransactionAbort()
Response,Write "Some of the information you " & "entered is not valid.<br>" 
Response.Write "Error Description: " & Err.Description & "<br>"
Response.Write "Click <a href='tt2.asp?StudentID=" & StudentID & "'>here</a> to update the information." 
Response.end
End Sub
Set oStudent = server.Create0bject("ClassRecords.CStudent") 
StudentID = Request("StudentID")
LastName = Request("LastName") 
FirstName = Request("FirstName") 
Grade = Request("Grade")
On Error Resume Next
Call oStudent.UpdateStudent(StudentID, LastName, FirstName, Grade)
If Err.Number <> 0 Then 
objectContext.setAbort
Else
objectContext.SetComplete
End If
%>

 


Your Ad Here
Not All Of Your Subscribers Use RSS - AWeber Email Marketing
Your Ad Here