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&"%' "

聯繫我們

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

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

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.