%@ TRANSACTION = Required LANGUAGE = "JScript" %>
Because the two database operations are wrapped within a shared ASP Transaction, both will be automatically rolled back to their previous state in the event of a failure. <% var objConn; // object for ADODB.Connection obj. var objRs; // object for recordset object. var strTitleID; // Create Connection and Recordset components. objConn = Server.CreateObject("ADODB.Connection"); objRs = Server.CreateObject("ADODB.Recordset"); //Connection string is OLEDB type instead of ODBC // Open ADO Connection using account "sa" // and blank password. objConn.Open("Provider=SQLOLEDB;User ID=sa;Initial Catalog=pubs;Data Source=" + Request.ServerVariables("SERVER_NAME")); objRs.ActiveConnection = objConn; // query title id objRs.Open("SELECT title_id FROM Titles"); // Get first title, mark up price by 10% if (! objRs.EOF) { strTitleID = objRs("title_id").Value; objConn.Execute("Update titles Set price =price+ price*(0.1) where title_id = "+ strTitleID); } //Get second title mark down price by 10 % objRs.MoveNext(); if (! objRs.EOF) { strTitleID = objRs("title_id").Value; objConn.Execute("Update titles Set price =price - price*(0.1) where title_id = "+ strTitleID); } %> <% // The Transacted Script Commit Handler. This sub-routine // will be called if the transacted script commits. function OnTransactionCommit() { Response.Write("
The update was successful."); } // The Transacted Script Abort Handler. This sub-routine // will be called if the script transacted aborts. function OnTransactionAbort() { Response.Write("
The update was not successful."); } %>