欢迎光临
我们一直在努力

关于客户端用ASP参生报表(高级篇)

建站超值云服务器,限时71元/月

上回曾贴一篇较简单的用asp+rds客户端参生报表

此回贴一篇较复杂的用asp+rds+组件客户端参生报表

错误说明:(若提示activex 元件无法参生 rds.dataspace)

ie需设置安全选项

操作:菜单工具->internet选项->安全性->自定义

设置:起始但activex不标示为安全->开启

原理说明:

客户端直接用rds产生recordset安全性不够,使用了

middle-tier automation components 后可大大增加安全性!

请看下文:

编写注册元件:

activex dll project:iacrdsobj.vbp

class module name:rsop

public function returnrs(strdb as variant, strsql as variant) as adodb.recordset

returns an adodb recordset.

on error goto ehgetrecordset

dim cn as new adodb.connection

dim rs as new adodb.recordset

dim strconnect as string

strconnect = "provider=sqloledb;server=server name ;uid=sa;pwd=; database=" & strdb & ";"

cn.open strconnect

these are not listed in the typelib.

rs.cursorlocation = aduseclient

using the unspecified parameters, an ado/r recordset is returned.

rs.open strsql, cn, adopenunspecified, adlockunspecified, adcmdunspecified

set returnrs = rs

exit function

ehgetrecordset:

err.raise err.number, err.source, err.description

end function

然后 make iacrdsobj.dll

若有错,请设置vb菜单project-refreence

增加 microsoft activex data object 2.6 library(当然数字要高一点)

然后 注册iacrdsobj.dll到数据库server(为安全,最好更改数据库uid最好不为sa)!

好,接下来看asp

long1.asp

<html>

<head>

<meta content="text/html; charset=gb2312" http-equiv=content-type>

<title>client use rds produce excel report</title>

</head>

<body bgcolor=skyblue topmargin=5 leftmargin="20" oncontextmenu="return false" rightmargin=0 bottommargin="0">

<div align="center"><center>

<table border="1" bgcolor="#ffe4b5" style="height: 1px; top: 0px" bordercolor="#0000ff">

<tr>

<td align="middle" bgcolor="#ffffff" bordercolor="#000080">

<font color="#000080" size="3">

client use rds produce excel report

</font>

</td>

</tr>

</table>

</div>

<form action="long1.asp" method="post" name="myform">

<div align=left>

<input type="button" value="query data" name="query" language="vbscript" onclick="fun_excel(1)" style="height: 32px; width: 90px">

<input type="button" value="clear data" name="clear" language="vbscript" onclick="fun_excel(2)" style="height: 32px; width: 90px">

<input type="button" value="excel report" name="report" language="vbscript" onclick="fun_excel(3)" style="height: 32px; width: 90px">

</div>

<div id="adddata"></div>

</form>

</body>

</html>

<script language="vbscript">

sub fun_excel(t)

dim rds,rs,df,serverstr

dim strsql,strrs

dim xlapp, xlbook, xlsheet1

serverstr="http://sql server name" the sql server name of register iacrdsobj.dll

use rds to produce client recordset

set rds = createobject("rds.dataspace",serverstr)

eg:set rds = createobject("rds.dataspace","http://iac_fa") iac_fa is the lan sql server name

eg:set rds = createobject("rds.dataspace","http://10.150.254.102") 10.150.254.102 is the lan sql server ip address

the register com

set df = rds.createobject("iacrdsobj.rsop", serverstr)

the query string of sql

strsql = "select top 8 * from jobs order by job_id"

the recordset

set rs = df.returnrs("pubs",strsql)

if t=1 then

if not rs.eof then

strrs="<table border=1><tr><td>job_id</td><td>job_desc</td><td>max_lvl</td><td>min_lvl</td></tr><tr><td>"+ rs.getstring(,,"</td><td>","</td></tr><tr><td>"," ") +"</td></tr></table>"

adddata.innerhtml=strrs

strrs=""

else

msgbox "no data in the table!"

end if

elseif t=2 then

strrs=""

adddata.innerhtml=strrs

elseif t=3 then

set xlapp = createobject("excel.application")

set xlbook = xlapp.workbooks.add

set xlsheet1 = xlbook.worksheets(1)

xlsheet1.cells(1,1).value ="the job table "

xlsheet1.range("a1:d1").merge

xlsheet1.cells(2,1).value = "job_id"

xlsheet1.cells(2,2).value = "job_desc"

xlsheet1.cells(2,3).value = "max_lvl"

xlsheet1.cells(2,4).value = "min_lvl"

cnt = 3

adapt to office 97 and 2000

do while not rs.eof

xlsheet1.cells(cnt,1).value = rs("job_id")

xlsheet1.cells(cnt,2).value = rs("job_desc")

xlsheet1.cells(cnt,3).value = rs("max_lvl")

xlsheet1.cells(cnt,4).value = rs("min_lvl")

rs.movenext

cnt = cint(cnt) + 1

loop

xlsheet1.application.visible = true

adapt to office 2000 only

xlsheet1.range("a3").copyfromrecordset rs

xlsheet1.application.visible = true

end if

rs.close

set rs=nothing

end sub

</script>

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 关于客户端用ASP参生报表(高级篇)
分享到: 更多 (0)

相关推荐

  • 暂无文章