菜鸟学ADO实例教程之ADO 删除记录

2008-02-23 09:31:02来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

  本站原创内容,转载请注明出处网页教学网

  我们可以使用SQL DELETE命令来删除表中的一个记录,和添加记录的方法一样,首先列出记录内容

  <html>

  <body>

  <%

  set conn=Server.CreateObject("ADODB.Connection")

  conn.Provider="Microsoft.Jet.OLEDB.4.0"

  conn.Open "e:/webjx/webjx.mdb"

  set rs=Server.CreateObject("ADODB.Recordset")

  rs.open "SELECT * FROM customers",conn

  %>

  <h2>数据库的内容列表</h2>

  <table border="1" width="100%">

  <tr>

  <%

  for each x in rs.Fields

   response.write("<th>" & ucase(x.name) & "</th>")

  next

  %>

  </tr>

  <% do until rs.EOF %>

  <tr>

  <form method="post" action="demo_delete.asp">

  <%

  for each x in rs.Fields

   if x.name="customerID" then%>

    <td>

    <input type="submit" name="customerID" value="<%=x.value%>">

    </td>

   <%else%>

    <td><%Response.Write(x.value)%></td>

   <%end if

  next

  %>

  </form>

  <%rs.MoveNext%>

  </tr>

  <%

  loop

  conn.close

  %>

  </table>

  </body>

  </html>

  具体的删除程序:demo_delete.asp

  <html>

  <body>

  <h2>Delete Record</h2>

  <%

  set conn=Server.CreateObject("ADODB.Connection")

  conn.Provider="Microsoft.Jet.OLEDB.4.0"

  conn.Open "e:/webjx/webjx.mdb"

  cid=Request.Form("customerID")

  if Request.form("companyname")="" then

   set rs=Server.CreateObject("ADODB.Recordset")

   rs.open "SELECT * FROM customers WHERE customerID='" & cid & "'",conn

   %>

   <form method="post" action="demo_update.asp">

   <table>

   <%for each x in rs.Fields%>

   <tr>

   <td><%=x.name%></td>

   <td><input name="<%=x.name%>" value="<%=x.value% >"></td>

   <%next%>

   </tr>

   </table>

   <br /><br />

   <input type="submit" value="删除记录">

   </form>

  <%

  else

   sql="DELETE FROM customers"

   sql=sql & " WHERE customersID='" & cid & "'"

   on error resume next

   conn.Execute sql

   if err<>0 then

    response.write("No update permissions!")

   else

    response.write("Record " & cid & " was deleted!")

   end if

  end if

  conn.close

  %>

  </body>

  </html>

  教程就写到这里,希望对初学ASP的朋友有所帮助,我就感到欣慰了,同时希望高手给指点。

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:菜鸟学ADO实例教程之ADO 更新记录

下一篇:让IIS Web服务器不再拒认ASP网页