<%@ LANGUAGE = VBScript %> <% 'Dr. Thomas E. Hicks - Trinity University - File AddUser1.asp 'Add Sarah [10, Very Cute] to table Users of the Security Database. 'Use the Record Set approach - approach ok for output, edit, and add!%> <% Option Explicit %> AddUser1.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 UsersRecSet ("Name") = "Sarah" UsersRecSet ("No")= 10 UsersRecSet ("Password") = "Very Cute" '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! - Added Sarah - Very Cute - 10 - AddUser1.asp
Dr. Thomas E. Hicks
Trinity University

The Database Is Now Updated! You Have Successfully Added Sarah!