 |
| 我的知识库 |
 |
|
|
使用Filter实现信息的二次检索 |
|
[ 作者: dnawo | 文章来源: 木子屋 | 点击数: 662 | 更新时间: 2007-10-13 17:41:58 ] |
思考一个问题:怎么实现在第一次检索的基础上进行二次检索? 中.国南通服务器网
通常,我们的做法是第一次检索时保存检索条件,在第二次行检索时组合两次检索条件对数据库进行一次新的查询,如: Www^Spdns^com
第一次检索:Select * from table where age>18 中.国.南通服务器网
第二次检索:Select * from table where age>18 and name like 'zh%' [南通服务器网]
这样做虽可以实现我们所要的结果,但效率上个人认为却大打了折扣! 中国南通服务器网
能不能缓存第一次检索的记录集,第二次检索时只在缓存的记录集上进行,而不是重新对数据库进行查询? Www_Spdns_com
RecordSet对象有个属性Filter,它的作用是通过添加条件以控制欲显示的记录集,但并不影响原本的记录集!我们来看下怎么用它实现二次检索: Www_Spdns_com
|
以下为引用的内容: <% 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 " Response.Write "----------------------------------
" Do while not ors.Eof Response.Write ors("name") & ":" & ors("age") & " " ors.MoveNext Loop Response.Write "总计:" & ors.RecordCount & " " Response.Write "----------------------------------
" 中.国.南通服务器网
Response.Write "二次检索:Filter(name like '王%') " Response.Write "----------------------------------
" 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") & " " ors.MoveNext Loop Response.Write "总计:" & ors.RecordCount & " " Response.Write "---------------------------------- "
Www@Spdns@com
ors.Close Set ors = Nothing oConn.Close Set oConn = Nothing %> Www^Spdns^com
|
中.国.南通服务器网
结果: Spdns^com
中国南通服务器网,为中文网站提供动力
共2页: 上一页 1 [2] 下一页
|
|
|
|
|