home *** CD-ROM | disk | FTP | other *** search
- <%@ LANGUAGE = VBScript %>
- <% Option Explicit %>
-
- <!--#include file="adovbs.inc"-->
-
- <HTML>
- <HEAD>
- <TITLE>Add/Delete Database Sample</TITLE>
- </HEAD>
-
- <BODY BGCOLOR="White" topmargin="10" leftmargin="10">
-
- <!-- Display Header -->
-
- <font size="4" face="Arial, Helvetica">
- <b>Add/Delete Database Sample</b></font><br>
-
- <hr size="1" color="#000000">
-
- <%
- Dim oConn
- Dim oRs
- Dim curDir
-
-
- ' Map authors database to physical path
-
- curDir = Server.MapPath("\iissamples\sdk\asp\database\authors.mdb")
-
-
- ' Create ADO Connection Component to connect with sample database
-
- Set oConn = Server.CreateObject("ADODB.Connection")
- oConn.Open "DBQ="& curDir &";Driver={Microsoft Access Driver (*.mdb)};DriverId=25;FIL=MS Access;"
-
-
- ' Create ADO Recordset Component, and associate it
- ' with ADO connection
-
- Set oRs = Server.CreateObject("ADODB.Recordset")
- Set oRs.ActiveConnection = oConn
-
-
- ' Get empty recordset
-
- oRs.Source = "SELECT * FROM authors Where 1=2"
- oRs.CursorType = adOpenStatic
- oRs.LockType = adLockOptimistic
- oRs.Open
-
-
- ' Add New Record
-
- oRs.Addnew
- oRs("Author").Value = "Paul Enfield"
- oRs("YearBorn").Value = 1967
- oRs.Update
-
-
- ' Output Result
-
- Response.Write("<p>Inserted Author: " & oRs("Author") & "," & oRs("YearBorn"))
-
-
- ' Close Recordset
-
- oRs.Close
-
-
- ' Create Recordset Component for deletion operation
-
- Set oRs = Server.CreateObject("ADODB.Recordset")
- Set oRs.ActiveConnection = oConn
-
-
- ' Create Recordset
-
- oRs.Source = "SELECT * FROM authors WHERE YearBorn=1967 and Author='Paul Enfield'"
- oRs.CursorType = adOpenForwardOnly
- oRs.LockType = adLockOptimistic ' use a locktype permitting deletions
- oRs.Open
-
-
- ' Delete record matching query
-
- oRs.Delete
- oRs.Update
-
-
- ' Output Status Result
-
- Response.Write("<p>Deleted Author: Paul Enfield, 1967")
- %>
- </BODY>
- </HTML>
-