欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

ASP編程入門進(jìn)階(二十):ADO組件之查詢數(shù)據(jù)記錄

 更新時(shí)間:2007年01月03日 00:00:00   作者:  
首先,了解下原理。
1,提供文本框進(jìn)行查詢內(nèi)容的輸入
2,將查詢信息提交頁(yè)面程序處理
3,程序頁(yè)主要作用:接受查詢信息,根據(jù)此信息調(diào)用特定的SQL查詢語(yǔ)句,得出查詢結(jié)果并能顯示。

其實(shí),主要精髓就是SQL語(yǔ)句的寫法上。
之前的提取為 "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&"%' "

下面通過(guò)一個(gè)例題來(lái)研究下
1,建立數(shù)據(jù)庫(kù)zipcode.mdb中的zip表
字段id,類型自動(dòng)編號(hào)(關(guān)鍵字)
字段placename,類型文本
字段province,類型文本
字段zipcode,類型文本
字段borough,類型文本

2,加入數(shù)據(jù)庫(kù)信息內(nèi)容
id 自動(dòng)編號(hào),無(wú)需加入
placename 對(duì)應(yīng)縣市
province 對(duì)應(yīng)省份
zipcode 對(duì)應(yīng)郵政編碼
borough 對(duì)應(yīng)區(qū)號(hào)

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,查詢輸入頁(yè)search.asp

[Ctrl+A 全部選擇進(jìn)行拷貝 提示:可先修改部分代碼,再點(diǎn)擊運(yùn)行]

5,信息查詢頁(yè),同樣是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&"%' "
rs.Open sql,conn,1,1
%>
<%
if rs.EOF and rs.BOF then
response.write ("未能查到")
else
Do Until rs.EOF
response.write("<hr>該地址是:"& rs("placename")&rs("zipcode"))
response.write("<br>所在省份是:"& rs("province"))
rs.MoveNext
Loop
end if
%>
<br><a href="search.asp">again</a>
<%
rs.close
Set rs = Nothing
conn.close
set conn=Nothing
else
%>
<form action="search.asp" method="post">
<input type="text" name="zipcode">
<input type="submit" name="submit" value="search">
</form>
<%end if%>



以上采用like意思表示進(jìn)行模糊查詢,要精確查詢則直接使用
sql = "Select * from zip where zipcode = '%"&whatzip&"%' "

當(dāng)然通過(guò)區(qū)號(hào)的查詢還沒(méi)添加,你可以自己試著完善,或者來(lái)個(gè)混合查詢、單獨(dú)查詢、模糊查詢以及精確查詢的大綜合了。
調(diào)試頁(yè)面參看。

相關(guān)文章

最新評(píng)論