使用Filter实现信息的二次检索
作者:dnawo 来源:蓝色理想 时间:2007-10-08 19:19:00
思考一个问题:怎么实现在第一次检索的基础上进行二次检索?
通常,我们的做法是第一次检索时保存检索条件,在第二次行检索时组合两次检索条件对数据库进行一次新的查询,如:
第一次检索:Select * from table where age>18
第二次检索:Select * from table where age>18 and name like 'zh%'
这样做虽可以实现我们所要的结果,但效率上个人认为却大打了折扣!
能不能缓存第一次检索的记录集,第二次检索时只在缓存的记录集上进行,而不是重新对数据库进行查询?
RecordSet对象有个属性Filter,它的作用是通过添加条件以控制欲显示的记录集,但并不影响原本的记录集!我们来看下怎么用它实现二次检索:
<%
Dim oConn,oRs
Set oConn=Server.CreateObject("ADODB.Connection")
oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("db1.mdb")
Set ors = Server.CreateObject("ADODB.RecordSet")
ors.Open "select * from t1 where age>20",oConn,1,2
Response.Write "一次检索:select * from t1 where age>20<br/>"
Response.Write "----------------------------------<br/><br/>"
Do while not ors.Eof
Response.Write ors("name") & ":" & ors("age") & "<br/>"
ors.MoveNext
Loop
Response.Write "总计:" & ors.RecordCount & "<br/>"
Response.Write "----------------------------------<br/><br/>"
Response.Write "二次检索:Filter(name like '王%')<br/>"
Response.Write "----------------------------------<br/><br/>"
ors.Filter = "name like '王%'"
If not(oRs.Eof and ors.Bof) Then ors.MoveFirst
Do while not ors.Eof
Response.Write ors("name") & ":" & ors("age") & "<br/>"
ors.MoveNext
Loop
Response.Write "总计:" & ors.RecordCount & "<br/>"
Response.Write "----------------------------------<br/>"
ors.Close
Set ors = Nothing
oConn.Close
Set oConn = Nothing
%>
结果:
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
mysql如何查询两个日期之间最大的连续登录天数
![](https://img.aspxhome.com/file/2023/3/121573_0s.jpg)
python实时分析日志的一个小脚本分享
python文件操作seek()偏移量,读取指正到指定位置操作
使用OpenCV实现人脸图像卡通化的示例代码
![](https://img.aspxhome.com/file/2023/7/82527_0s.jpg)
详解如何在nuxt中添加proxyTable代理
浅谈webpack编译vue项目生成的代码探索
![](https://img.aspxhome.com/file/2023/0/56500_0s.png)
MySQL 两张表数据合并的实现
![](https://img.aspxhome.com/file/2023/4/128054_0s.png)
web程序员的思考
MySQL对于各种锁的概念理解
mysql 5.5 安装配置方法图文教程
![](https://img.aspxhome.com/file/2023/6/65696_0s.png)
Vue-cli创建项目从单页面到多页面的方法
![](https://img.aspxhome.com/file/2023/7/125287_0s.png)
python使用WMI检测windows系统信息、硬盘信息、网卡信息的方法
flask项目集成swagger的方法
![](https://img.aspxhome.com/file/2023/1/68381_0s.png)
php字符串截取函数mb_substr用法实例分析
前后端分离和跨域问题的详细解决方案(CORS的原理)
![](https://img.aspxhome.com/file/2023/7/55307_0s.png)
Django项目后台不挂断运行的方法
python 调整图片亮度的示例
![](https://img.aspxhome.com/file/2023/7/95507_0s.png)
python实现报表自动化详解
![](https://img.aspxhome.com/file/2023/3/123663_0s.jpg)
FCKEidtor 自动统计输入字符个数(IE)
![](https://img.aspxhome.com/file/2023/0/71290_0s.gif)