<%@ LANGUAGE = VBScript %> <% 'Dr. Thomas E. Hicks - Trinity University - File DeleteUser2.asp 'Delete the first user from the table Users in the Security Database where 'the OldUserName from form DeleteUser2.html matches theName. 'Use the Record Set approach - approach ok for output, edit, and add!%> <% Option Explicit %> DeleteUser2.asp <% Dim Conn, UsersRecSet, Query, Done, FoundIt '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 ("Name") = Request("OldUserName") 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! [<%Request("OldUserName")%>] Deleted - DeleteUser2.asp
Dr. Thomas E. Hicks
Trinity University

<% If FoundIt Then %>

Record [<% = Request("OldUserName") %>] Has Been Deleted!

<% Else %>

Record [<% = Request("OldUserName") %>] Was Not Found!

<% End If %>