home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / software / pelne / optionp / iis4_07.cab / FundTransfer_JScript.asp < prev    next >
Text File  |  1997-10-25  |  3KB  |  112 lines

  1. <%@ TRANSACTION=Required LANGUAGE="JScript" %>
  2.  
  3. <!--#include file="adojavas.inc"-->
  4.  
  5. <HTML>
  6.     <HEAD>
  7.         <TITLE>Transactional Database Update</TITLE>
  8.     </HEAD>
  9.  
  10.     <BODY BGCOLOR="White" topmargin="10" leftmargin="10">
  11.  
  12.  
  13.         <!-- Display Header -->
  14.  
  15.         <font size="4" face="Arial, Helvetica">
  16.         <b>Transactional Database Update</b></font><br>
  17.       
  18.         <hr size="1" color="#000000">
  19.  
  20.  
  21.         <!-- Brief Description blurb.  -->
  22.  
  23.         This is a simple example demonstrating how to transactionally 
  24.         update a SQL 6.5 database using ADO and Transacted ASP.
  25.         The example will obtain information regarding a book sale from 
  26.         the SQL 6.5 "Pubs" database.  It will then increment the quantity 
  27.         of books sold by one, as well as change the zip-code of the store 
  28.         in which the book was sold.  
  29.  
  30.         <p> Because the two database operations are wrapped
  31.         within a shared ASP Transaction, both will be automatically rolled
  32.         back to their previous state in the event of a failure.
  33.  
  34.  
  35.     <%
  36.         var oConn;        // object for ADODB.Connection obj
  37.         var oRs;        // object for recordset object
  38.         var oRs2;        // object for recordset object
  39.  
  40.  
  41.         // Create Connection and Recordset components
  42.  
  43.         oConn = Server.CreateObject("ADODB.Connection");
  44.         oRs   = Server.CreateObject("ADODB.Recordset");
  45.         oRs2  = Server.CreateObject("ADODB.Recordset");
  46.  
  47.  
  48.         // Open ADO Connection using account "sa"
  49.         // and blank password
  50.  
  51.         oConn.Open("DSN=LocalServer;UID=sa;PWD=;DATABASE=pubs");
  52.         oRs.ActiveConnection = oConn;
  53.         oRs2.ActiveConnection = oConn;
  54.  
  55.  
  56.  
  57.         // Find a random book sale 
  58.  
  59.         oRs.Source = "SELECT * FROM sales";
  60.         oRs.CursorType = adOpenStatic;            // use a cursor other than Forward Only
  61.         oRs.LockType = adLockOptimistic;        // use a locktype permitting insertions
  62.         oRs.Open();
  63.  
  64.  
  65.         // Change quantity sold
  66.  
  67.         if (! oRs.EOF) {
  68.             oRs("qty").Value = oRs("qty").Value + 1;
  69.             oRs.Update();
  70.         }
  71.             
  72.  
  73.             
  74.         // Find the store in which the book was sold
  75.  
  76.         oRs2.Source = "SELECT * FROM stores where stor_id='" + oRs("stor_id") + "'";
  77.         oRs2.CursorType = adOpenStatic;            // use a cursor other than Forward Only
  78.         oRs2.LockType = adLockOptimistic;        // use a locktype permitting insertions
  79.         oRs2.Open();
  80.  
  81.  
  82.         // Change zip code
  83.  
  84.         if (! oRs2.EOF) {
  85.             oRs2("Zip").Value = new Number(oRs2("Zip").Value) + 1;
  86.             oRs2.Update();
  87.         }
  88.     %>
  89.  
  90.  
  91.     </BODY>
  92. </HTML>
  93.  
  94.  
  95. <%
  96.     // The Transacted Script Commit Handler.  This sub-routine
  97.     // will be called if the transacted script commits.
  98.  
  99.     function OnTransactionCommit()
  100.     {
  101.     Response.Write("<p><b>The update was successful</b>.");
  102.     }
  103.  
  104.  
  105.     // The Transacted Script Abort Handler.  This sub-routine
  106.     // will be called if the script transacted aborts
  107.  
  108.     function OnTransactionAbort()
  109.     {
  110.     Response.Write("<p><b>The update was not successful</b>.");
  111.     }
  112. %>