首先,了解下原理。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" thenwhatzip=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 thenresponse.write ("未能查到")elseDo Until rs.EOFresponse.write("<hr>该地址是:"& rs("placename")&rs("zipcode"))response.write("<br>所在省份是:"& rs("province"))rs.MoveNextLoopend if%><br><a href="search.asp">again</a><%rs.close Set rs = Nothingconn.close set conn=Nothingelse%><form action="search.asp" method="post"><input type="text" name="zipcode"><input type="submit" name="submit" value="search"></form><%end if%>以上采用like意思表示进行模糊查询,要精确查询则直接使用sql = "Select * from zip where zipcode = '%"&whatzip&"%' "当然通过区号的查询还没添加,你可以自己试着完善,或者来个混合查询、单独查询、模糊查询以及精确查询的大综合了。调试页面参看。
推荐阅读
6行代码实现无组件上传(author:stimson)
原理代码:
strFileName = Request.QueryString("file1")Set objStream = Server.CreateObject("ADODB.Stream")objStream.Type = 1 ' adTypeBinaryobjStream.OpenobjStream.LoadFromFile strFileNameobjStream.>>>详细阅读
本文标题:ASP编程入门进阶(二十):ADO组件之查询数据记录
地址:http://www.17bianji.com/kaifa2/ASP/32848.html
1/2 1