仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 2036|回复: 19
打印 上一主题 下一主题

[学习教程] ASP编程:先贴一篇较复杂的用ASP+RDS客户端参生...

[复制链接]
谁可相欹 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-2-3 23:32:21 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
使用filesystemobject,可以对服务器上的文件进行操作,浏览、复制、移动、删除等。有ado的支持,asp对数据库的操作非常得心应手。你甚至可以像使用本地数据库那样,管理远程主机上的数据库,对表格、记录进行各种操作。   上回曾贴一篇较复杂的用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" style="HEIGHT: 32px; WIDTH: 90px">
<input type="button" value="Clear Data" name="Clear" language="vbscript" style="HEIGHT: 32px; WIDTH: 90px">
<input type="button" value="Excel Report" name="report" language="vbscript" 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>
帮助用户快速实现各种应用服务,ASP商有整合各方面资源的能力,可在短期内为用户提供所需的解决方案。例如,典型的ERP安装,如果要在客户端安装的话需要半年到二年的时间,但是美国的一些ASP商如USI和CORIO能在90—120天内提供ERP应用方案。
谁可相欹 该用户已被删除
沙发
 楼主| 发表于 2015-3-21 18:30:15 | 显示全部楼层
从事这个行业,那么你可以学ASP语言,简单快速上手,熟练dreamweav排版,写asp代码,熟练photoshop处理图片,打好基础就行了
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-5-12 17:50

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表