菜鳥學ADO執行個體教程之ADO 刪除記錄

來源:互聯網
上載者:User
ado|教程

  本站原創內容,轉載請註明出處網頁教學網

  我們可以使用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的朋友有所協助,我就感到欣慰了,同時希望高手給指點。



相關文章

Beyond APAC's No.1 Cloud

19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。