%@ LANGUAGE = VBScript %>
<% 'Dr. Thomas E. Hicks - Trinity University - File DeleteUser1.asp
'Delete IDNo 2 from the table Users in the Security Database.
'Use the Record Set approach - approach ok for output, edit, and add!%>
<% Option Explicit %>
<% 'Only one scripting language can be used at a time. The choices are
'VBScript and Microsofts version of JavaScript which it calls JScript.
'The line below establishes VBScript as the scripting language for this page.
'This line should be near the top of each and every ASP page. %>
DeleteUser1.asp
<%
Dim Conn, UsersRecSet, Query, Done, FoundIt, OldUserIDNo
'Record To Delete
OldUserIDNo = 2
'Create a Connection Object
Set Conn = Server.CreateObject ("ADODB.Connection")
'Open Security ODBC with the Connection Object
Conn.Open "Security"
'Begin a new transaction
Conn.BeginTrans
'Define the Query - declared as a variable because often long!
Query = "SELECT * FROM USERS"
'Create a record set object
Set UsersRecSet = Server.CreateObject ("ADODB.Recordset")
'The open below locks the data and fills the Record Set.
UsersRecSet.Open Query, Conn, adOpenStatic, adLockOptimistic
'Navigate to the record in the record set
Done = FALSE
FoundIt = FALSE
Do WHILE NOT Done
If UsersRecSet.EOF Then
Done = TRUE
ElseIf UsersRecSet ("IDNo") = OldUserIDNo Then
Done = TRUE
FoundIt = TRUE
Else
UsersRecSet.MoveNext
End If
Loop
If FoundIt Then
' Delete the current record from the record set
UsersRecSet.Delete
End If
'Save changes to database and end the transaction
Conn.CommitTrans
'Close the RecordSet - optional?
UsersRecSet.Close
'Close the Connection
Conn.Close
%>
Delete User Results! - IDNo = 2 Deleted - DeleteUser1.asp
Dr. Thomas E. Hicks
Trinity University
<% If FoundIt Then %>
Record [<% = OldUserIDNo %>] Has Been Deleted!
<% Else %>
Record [<% = OldUserIDNo %>] Was Not Found!
<% End If %>