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

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