|
Jun
07
|
|
调用:
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")
%>From 迷途知返, post [纯属无聊]asp access数据库操作类
RELATED POSTS:


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