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