加入收藏 | 设为首页 | 会员中心 | 我要投稿 银川站长网 (https://www.0951zz.com/)- 云通信、基础存储、云上网络、机器学习、视觉智能!
当前位置: 首页 > 站长学院 > Asp教程 > 正文

使用Filter达成信息的二次检索

发布时间:2023-09-15 12:57:36 所属栏目:Asp教程 来源:
导读:思考一个问题:怎么实现在第一次检索的基础上进行二次检索?通常,我们的做法是第一次检索时保存检索条件,在第二次行检索时组合两次检索条件对数据库进行一次新的查询,如:第一次检索:Select * from table where

思考一个问题:怎么实现在第一次检索的基础上进行二次检索?

通常,我们的做法是第一次检索时保存检索条件,在第二次行检索时组合两次检索条件对数据库进行一次新的查询,如:

第一次检索: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

%>

(编辑:银川站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章