<%@ LANGUAGE = VBScript %> <% 'Dr. Thomas E. Hicks - Trinity University - File AddUser2.asp - QUERY 'Add a new record to table Users of the Security Database in which the 'UserName, UserNo, and UserPassword [of AddUser2.html] are placed in 'the respective Name, No, and Password fields. 'Use the Record Set approach - approach ok for output, edit, and add!%> <% Option Explicit %> AddUser2.asp <% Dim Conn, UsersRecSet, Query '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 two options that we shall use to lock the database are 'adLockOptimistic - add, edit, or delete records from database 'adLockReadOnly - retrieving data only 'The open below locks the data and fills the Record Set. UsersRecSet.Open Query, Conn, adOpenStatic, adLockOptimistic 'Add a new record to the record set - move ptr to that record UsersRecSet.AddNew 'Fill the new record set from the form information UsersRecSet ("Name") = Request("UserName") UsersRecSet ("No")= Request("UserNo") UsersRecSet ("Password") = Request("UserPassword") 'Save those changes made to the current record [in the record set] UsersRecSet.Update 'Save changes to database and end the transaction Conn.CommitTrans 'Close the RecordSet - optional? UsersRecSet.Close 'Close the Connection Conn.Close %>
Add User Results! - AddUser2.asp
Dr. Thomas E. Hicks
Trinity University

The Database Is Now Updated! You Have Successfully Added The New Record!