home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 February / CHIP_2_98.iso / software / pelne / optionp / iis4_06.cab / samp7q0j.asp < prev    next >
Text File  |  1997-10-15  |  3KB  |  42 lines

  1.  <% If Request("DontFrame")<>1 Then Response.Redirect "/iissamples/sdk/asp/docs/SampFram.asp?ovfile=/iishelp/iis/htm/sdk/samp7q0j.asp&srcfile=Database/AddDelete" %>
  2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
  3. <HTML>
  4. <HEAD>
  5. <META HTTP-EQUIV="Content-Type" Content="text-html; charset=Windows-1252">
  6. <title>Add/Delete Records</title>
  7. <script language="JavaScript">
  8.  
  9.     szNavVersion = navigator.appVersion
  10.  
  11.     if (navigator.appName == "Microsoft Internet Explorer") {
  12.     if (szNavVersion.indexOf ("4.") >= 0) {
  13.         document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/spidie4.css">');
  14.     } else {
  15.         document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/spidie3.css">');
  16.     }
  17.     }
  18.     else if (navigator.appName == "Netscape") {
  19.     document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/spidie4.css">');
  20.     }
  21.     else {
  22.     document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/spidie3.css">');
  23.     }
  24.  
  25. </script>
  26. <META NAME="DESCRIPTION" CONTENT="Internet Information Server reference information"></HEAD>
  27. <BODY BGCOLOR=#FFFFFF TEXT=#000000>
  28. <font face="Verdana, Arial, Helvetica">
  29. <h3><a name="_add_delete_records"></a>Add/Delete Records</h3>
  30. <p>
  31. 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>
  32. <p>
  33. 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>
  34. <p>
  35. 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>
  36. <p>
  37. <b>Note</b>  ODBC must be properly configured on the server before this sample will run properly. </p>
  38. <hr class="iis" size="1">
  39. <p align="center"><em><a href="/iishelp/common/colegal.htm">© 1997 by Microsoft Corporation. All rights reserved.</a></em></p>
  40. </BODY>
  41. </HTML>
  42.