Categories: ASP | Tags: | Views: 2,832

调用:

db.query("select * from News")
rs = db.fetch_all
for i=0 to db.num_rows - 1
    response.write rs(1,i) & "<br>"
next
 
db.query("select * from admin")
response.write db.get_value("id")

类代码:

<%
class DBConn
    private conn
    private rs
 
    private sub Class_Initialize
        Set conn = Server.CreateObject("ADODB.Connection")
        set rs = Server.CreateObject("adodb.recordset")
    end sub
 
    Private Sub Class_Terminate
        rs.close
        set rs = nothing
        conn.close
        set conn = nothing
    end sub
 
    private function indexOfCols(colname)
        dim i
        for i = 0 to rs.fields.count - 1
            if rs(i).name = colname then
                indexOfCols = i
                exit function
            end if 
        Next
    end function
 
    public sub query(sql)
        if rs.state = 1 then rs.close
        rs.open sql,conn,1,3
    end sub
 
    public function get_value(colname)
        get_value = rs(colname) 
    end function
 
    public function get_value2(colname, row)
        dim rows
        rs.movefirst
        rows = rs.getrows()
        get_value2 = rows(indexOfCols(colname), row)
    end function
 
    public function get_value3(col, row)
        dim rows
        rs.movefirst
        rows = rs.getrows()
        get_value3 = rows(col, row)
    end function
 
    public function fetch_array()
        redim ret(rs.fields.count)
        dim i
        for i=0 to ubound(ret) - 1
            ret(i) = rs(i)
        next
        fetch_array = ret
    end function
 
    public function num_rows()
        num_rows = rs.recordcount
    end function
 
    public function fetch_all()
        rs.movefirst
        fetch_all = rs.getrows()
    end function
 
    public function num_fields()
        num_fields = rs.fields.count
    end function
 
    public sub open(connstr)
        conn.open connstr
    end sub
 
end class
 
dim db
set db = new DBConn
db.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("#db.mdb")
 
%>

RELATED POSTS:

  1. Jmail邮件发送系统例子
  2. Windows代理快速切换VBS版
  3. ASP的分页函数
  4. php的mysql数据库操作类
  5. JavaScript中的print_r
  6. asp分页类
  1. May 19th, 2011 at 21:35
    Reply | Quote | #1

    蛮不错的啊,哥们.向你学习了,有好的asp类都发一下教一下我们新手.

3 trackbacks

  1. asp分页类 | 迷途知返 Pingback | 2010/06/10
  2. SHANE Trackback | 2010/07/01
  3. laser Trackback | 2010/08/30
;) :| :x :twisted: :roll: :oops: :o :mrgreen: :lol: :idea: :evil: :cry: :arrow: :P :D :?: :? :) :( :!: 8O 8)

你可以使用@somebody:开头, 来邮件通知somebody你回复了他的留言(用户名区分大小写).