ASP參生報表用戶端用(進階篇)

來源:互聯網
上載者:User
進階|用戶端 上回曾貼一篇較簡單的用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)
xl



相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.