<% If Request("DontFrame")<>1 Then Response.Redirect "/iissamples/sdk/asp/docs/SampFram.asp?ovfile=/iishelp/iis/htm/sdk/samp7q0j.asp&srcfile=Database/AddDelete" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
This sample illustrates the techniques you need to know in order to add and delete records from a database using ASP and ADO. First, <b>CreateObject</b> is used to create an instance of the <b>Connection</b> object, which in turn is used to open a connection to the ODBC data source. <b>CreateObject</b> is used again, this time to create an empty <b>Recordset</b> object. The <b>ActiveConnection</b> property is set to refer to the new <b>Connection</b> object. </p>
<p>
The <b>Recordset.Source</b> property is assigned a SQL <b>SELECT</b> string that will, by design, not find anything when the <b>Recordset.Open</b> method is executed. This has the effect of creating an empty recordset with the proper field format of the entries in the table accessed in the SQL string. The <b>AddNew</b> method of the <b>Recordset</b> object is called, new field values are added, and the <b>Recordset.Update</b> method writes the changes back to the database. A quick <b>Response.Write</b> confirms that the record was indeed written correctly, and the recordset is closed. </p>
<p>
At this point, another <b>Recordset</b> object instance is created and opened with the <b>Recordset.Open</b> method. The record just added is selected, then deleted using the <b>Recordset.Delete</b> method. The change is saved back to the database using <b>Update</b> method, and the script terminates. </p>
<p>
<b>Note</b> ODBC must be properly configured on the server before this sample will run properly. </p>