• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: 小 中 大 | 推荐给好友 上一篇 | 下一篇

asp对象化之:数据库结果集合操作类

发布: 2007-6-30 18:56 | 作者: admin | 来源: | 查看: 19次 | 进入软件测试论坛讨论

领测软件测试网 <% 

’************************************************************* 
’转发时请保留此声明信息,这段声明不并会影响你的速度! 
’************************************************************* 


’************************************************************* 
’@author:                        面条 
’@realname:                        徐仁禄 
’@email:                        [email protected] 
’@QQ:                            55547082 
’@Homepage:                        http://www.ksdn.net 
’@版权申明: 
’            非盈利性质团体或者个人可以免费使用. 
’************************************************************* 


’************************************************************* 
’************************************************************* 
’************************************************************* 
class Rsclass 
    private iRs 
    private isql 
    private iconn 
    private closeConn 
    private openConn 

’************************************************************* 
’        进行初始化,建立iconn和irs对象. 
’************************************************************* 
    Private Sub Class_initialize()  
        set iconn=server.createobject("adodb.connection") 
        set irs=server.createobject("adodb.recordset") 
    End Sub  
     
    public sub connect(connstr) 
        err.clear 
        on error resume next 
        iconn.open connstr 
        if err.number<>0 then response.write "数据联接出错了." 
    end sub 
     
    public property let conn(connection) 
        set iconn=connection        ’通过外界传入一个数据库联接. 
    end property 
     
     
     
    Private Sub Class_Terminate()  
        on error resume next 
        irs.close 
        iconn.close 
        set iconn=nothing 
        set irs=nothing 
    End Sub  

’************************************************************* 
’        内容:实现统计功能,一般用select count(*) from table where id>54类似的sql语句. 
’************************************************************* 
    public function getCountBysql(sql) 
        on error resume next 
        dim count 
        count=iconn.execute(sql)(0) 
        getCountBysql=count 
        iconn.close 
    end function  
     
     
     

’************************************************************* 
    public function deleteBySql(sql) 
        err.clear 
        on error resume next 
        iconn.execute(sql) 
        if err.errcode<>0 then 
            deleteBysql=false 
            exit function 
        end if 
        deleteBySql=true 
    end function  


’************************************************************* 
    public function deleteByid(table,column,value) 
        err.clear 
        on error resume next 
        iconn.execute("delete from "&table & " where "&column & "=’"&value & "’") 
        if err.errcode<>0 then 
            deleteByid=false 
            exit function 
        end if 
        deleteByid=true 
    end function  


’************************************************************* 
’        返回一个词典,用这个词典来装载要添加的对象. 
    public function getdict() 
        set getdict=server.createobject("scripting.dictionary")     
    end function  

’************************************************************* 
’        增加新的记录. 
    public function add(obj,table) 
        dim item 
        isql="select * from " & table 
        response.write isql 
        iRs.open isql,iconn,1,3 
        irs.addnew 
        for each item in obj 
            irs(item)=obj(item) 
        next  
        irs.update 
        irs.close 
    end function  
     
     

’************************************************************* 
’        得到查询得返回值 
    public function getquery(sql) 
        iRs.open sql,iconn,1,1  
        if irs.eof and irs.bof then 
            getquery=null 
        else 
            set getquery=irs 
        end if 
    end function  

    public function getqueryPage(sql,pageNum,PageSize) 
        on error resume next 
        iRs.pageSize=pageSize 
        iRs.open sql,iconn,1,1  
        iRs.AbsolutePage=pageNum 
        if irs.eof and irs.bof then 
            getqueryPage=null 
        else 
            set getqueryPage=irs 
        end if 
         
        response.write "<span style=’color:green;’>"& err.number & err.description &"</span>" 
    end function  
     
     
’************************************************************* 
’        让结果集移动到第n页. 
    public function setPage(pageNum,PageSize) 
        on error resume next 
        iRs.moveFirst 
        iRs.move((pageNum-1)*PageSize) 
    end function  


end class 



’************************************************************* 
用法示例: 
dim cstr 
dim path 
path=server.mappath("2data.mdb") 
cstr= "DBQ="+path+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};" 
dim rec 
set rec=new RsClass 
rec.connect(cstr) 


response.write "************************" 
set tt=rec.getqueryPage("select top 8 * from help",2,4) 
response.write tt.recordcount & "<br>" 
do while not tt.eof  
    response.write tt(0) &"<br>" 
    tt.movenext 
loop 
tt.movefirst 
tt.close 
%> 

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:[email protected] 电话:010-51297073

软件测试 | 领测国际 | ISTQB | ISTQB官网 | TMMi | TMMi认证 | 国际软件测试工程师认证 | 领测软件测试网