ASP編程入門進階(二十):ADO組件之查詢資料記錄
來源:互聯網
上載者:User
首先,瞭解下原理。
1,提供文字框進行查詢內容的輸入
2,將查詢資訊提交頁面程式處理
3,程式頁主要作用:接受查詢資訊,根據此資訊調用特定的SQL查詢語句,得出查詢結果並能顯示。
其實,主要精髓就是SQL語句的寫法上。
之前的提取為 "select * form whattable where id="&id
插入為 "insert into whattable(xx_rs) values(' "&content&" ')"
刪除為 "delete from whattable where id="&id
修改為 "update whattable set xx_rs=' "&log_content&" ' where id="&id
則查詢為 "select * form whattable where xx_rs like '%"&wahtkey&"%' "
下面通過一個例題來研究下
1,建立資料庫zipcode.mdb中的zip表
欄位id,類型自動編號(關鍵字)
欄位placename,類型文本
欄位province,類型文本
欄位zipcode,類型文本
欄位borough,類型文本
2,加入資料庫資訊內容
id 自動編號,無需加入
placename 對應縣市
province 對應省份
zipcode 對應郵遞區號
borough 對應區號
3,串連檔案conn.asp
<%
db_path = "zipcode.mdb"
Set conn= Server.CreateObject("ADODB.Connection")
connstr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath(db_path)
conn.Open connstr
%>
4,查詢輸入頁search.asp
<form action="search.asp" method="post">
<input type="text" name="zipcode">
<input type="submit" name="submit" value="search">
</form>
[Ctrl+A 全部選擇 提示:你可先修改部分代碼,再按運行]
5,資訊查詢頁,同樣是search.asp
<!--#include file="conn.asp" -->
<%
if request.form("submit")="search" then
whatzip=request.form("zipcode")
Set rs = Server.CreateObject ("ADODB.Recordset")
sql = "Select * from zip where zipcode like '%"&whatzip&"%' "