test.asp[code]<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html><head>
<title>activex组件应用例子一</title></head>
<%
'---------------------------------------------------------
'activex组件应用例子一
'读取sql server 7 pubs数据库中authors表并分页显示
'asp文件中负责调用并前台数据检验,这里主要指page参数
'该例子完全使用activex组件来完成功能,速度快,保密性好,但页面定制能力差
'jjx by 2000/4/15
'----------------------------------------------------------------
dim blnerrorif not isempty(request("page")) then
if not isnumeric(request("page")) then
response.write "参数错误!"
blnerror=true
end ifend ifif not blnerror then
dim objloop
set objloop=server.createobject("performance.loop")
objloop.list()
set objloop=nothingend if%>
</body></html>[/code]vb loop class file创建一个performance activex dll项目,引用microsoft active
server pages library和microsoft activex databae object。
填加一个class,命名为loop[code]option explicit
dim myscriptingcontext as scriptingcontextdim myrequest as requestdim myresponse as response
sub onendpage()
set myresponse = nothing
set myrequest = nothing
set myscriptingcontext = nothing
end sub
sub onstartpage(passedscriptingcontext as scriptingcontext)
set myscriptingcontext = passedscriptingcontext
set myrequest = myscriptingcontext.request
set myresponse = myscriptingcontext.response
end sub
function list()
dim con as new adodb.connection
dim rs as new adodb.recordset
dim i as integer
dim j as integer
dim intpage as integer
dim intpagesize as integer
dim intpagecount as integer
dim strscriptname as string
dim intpos as integer
dim intfieldcount as integer
strscriptname = myrequest.servervariables("script_name")
intpos = instrrev(strscriptname, "/")
if intpos <> 0 then
strscriptname = mid(strscriptname, intpos + 1)
end if
if isempty(myrequest("page")) then
intpage = 1
else
intpage = cint(myrequest("page"))
end if
intpagesize = 10
con.open "provider=sqloledb.1;persist security info=false;user id=sa;initial catalog=pubs;data source=
(local)"
rs.open "select * from authors", con, adopenstatic
intfieldcount = rs.fields.count
with myresponse
.write "<table border=1>"
if not (rs.eof and rs.bof) then
rs.pagesize = 10
rs.absolutepage = intpage
intpagecount = rs.pagecount
if intpage > intpagecount then
intpage = intpagecount
end if
if intpagecount > 1 then
.write "<tr><td colspan=" & intfieldcount & ">"
for i = 1 to intpagecount
if intpage = i then
.write "[" & i & "] "
else
.write "<a href=" & strscriptname & "?page=" & i & ">[" & i & "]</a> "
end if
next
.write "</td></tr>"
end if
end if
.write "<tr>"
for i = 0 to intfieldcount - 1
.write "<th>" & rs(i).name & "</th>"
next
.write "</tr>"
for i = 1 to intpagesize
if rs.eof then
exit for
end if
.write "<tr>"
for j = 0 to intfieldcount - 1
.write "<td>" & rs(j).value & "</td>"
next
.write "</tr>"
rs.movenext
next
.write "</table>"
end with
rs.close
set rs = nothing
con.close
set con = nothing
end function
[/code]
(责任编辑:admin) |