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

  1. <%@ LANGUAGE = JScript %>
  2.  
  3. <!--#include file="adojavas.inc"-->
  4.  
  5. <HTML>
  6.     <HEAD>
  7.         <TITLE>Add/Delete Database Sample</TITLE>
  8.     </HEAD>
  9.  
  10.     <BODY BGCOLOR="White" topmargin="10" leftmargin="10">
  11.  
  12.         <!-- Display Header -->
  13.  
  14.         <font size="4" face="Arial, Helvetica">
  15.         <b>Add/Delete Database Sample</b></font><br>
  16.       
  17.         <hr size="1" color="#000000">
  18.  
  19.  
  20.         <%
  21.             var oConn;    
  22.             var oRs;        
  23.             var curDir;    
  24.  
  25.             
  26.             // Map authors database to physical path
  27.             
  28.             curDir = Server.MapPath("\\iissamples\\sdk\\asp\\database\\authors.mdb");
  29.  
  30.  
  31.             // Create ADO Connection Component to connect
  32.             // with sample database
  33.             
  34.             oConn = Server.CreateObject("ADODB.Connection");
  35.             oConn.Open("DBQ="+curDir+";Driver={Microsoft Access Driver (*.mdb)};DriverId=25;FIL=MS Access;")
  36.  
  37.  
  38.             // Create ADO Recordset Component, and associate
  39.             // it with ADO connection
  40.             
  41.             oRs = Server.CreateObject("ADODB.Recordset");
  42.             oRs.ActiveConnection = oConn;
  43.             
  44.             
  45.             // Get empty recordset
  46.             
  47.             oRs.Source = "SELECT * FROM authors Where 1=2";
  48.             oRs.CursorType = adOpenStatic;            
  49.             oRs.LockType = adLockOptimistic;
  50.             oRs.Open();
  51.  
  52.  
  53.             // Add New Record
  54.             
  55.             oRs.Addnew();                            
  56.             oRs("Author").Value = "Paul Enfield";
  57.             oRs("YearBorn").Value = 1967;            
  58.             oRs.Update();
  59.  
  60.  
  61.             // Output Result
  62.             
  63.             Response.Write("<p>Inserted Author: "+oRs("Author")+"," + oRs("YearBorn"));
  64.  
  65.  
  66.             // Close Recordset
  67.             
  68.             oRs.Close();
  69.  
  70.             
  71.             // Create Recordset Component for deletion operation
  72.             
  73.             oRs = Server.CreateObject("ADODB.Recordset");
  74.             oRs.ActiveConnection = oConn;
  75.         
  76.         
  77.             // Create Recordset
  78.             
  79.             oRs.Source = "SELECT * FROM authors WHERE YearBorn=1967 and Author='Paul Enfield'";    
  80.             oRs.CursorType = adOpenForwardOnly;
  81.             oRs.LockType = adLockOptimistic;
  82.             oRs.Open();
  83.  
  84.  
  85.             // Delete record matching query
  86.             
  87.             oRs.Delete();
  88.             oRs.Update();
  89.  
  90.             
  91.             // Output Status Result
  92.             
  93.             Response.Write("<p>Deleted Author: Paul Enfield, 1967");
  94.         %>
  95.     </BODY>
  96. </HTML>
  97.