詳解Command對象記錄說明介紹
ADO Command對象用于執(zhí)行面向數(shù)據(jù)庫的一次簡單查詢。此查詢可執(zhí)行諸如創(chuàng)建、添加、取回、刪除或更新記錄等動作。如果該查詢用于取回數(shù)據(jù),此數(shù)據(jù)將以一個 RecordSet 對象返回。#t#
Command對象的主要特性是有能力使用存儲查詢和帶有參數(shù)的存儲過程。我們希望更新 Northwind 數(shù)據(jù)中 Customers 表的某條記錄。首先我們需要創(chuàng)建一個表格,來列出 Customers 中的所有記錄。
- <html>
- <body>
- <%
- set conn=Server.CreateObject("ADODB.Connection")
- conn.Provider="Microsoft.Jet.OLEDB.4.0"
- conn.Open "c:/webdata/northwind.mdb"
- set rs=Server.CreateObject("ADODB.Recordset")
- rs.open "SELECT * FROM customers",conn
- %>
- <h2>List Database</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_update.asp">
- <%
- for each x in rs.Fields
- if lcase(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>
如果用戶點擊Command對象列中的按鈕,會打開一個新文件 "demo_update.asp"。此文件包含了創(chuàng)建輸入域的源代碼,這些輸入域基于數(shù)據(jù)庫中記錄的字段,同時也含有一個保存修改的“更新按鈕”。