DataSpace 对象和 CreateObject 方法范例 (VBScript)

以下范例显示如何使用具有默认业务对象 RDSServer.DataFactory RDS.DataSpace CreateObject 方法。要测试该范例,请将其剪切并粘贴到标准 HTML 文档的 <Body></Body> 标记之间,然后将其命名为 ADCapi8.asp。ASP 脚本将标识服务器。

<Center><H2>RDS API Code Examples </H2>
<HR><H3>Using Query Method of RDSServer.DataFactory</H3><!-- RDS.DataSpace  ID ADS1-->
<OBJECT ID="ADS1" WIDTH=1 HEIGHT=1
CLASSID="CLSID:BD96C556-65A3-11D0-983A-00C04FC29E36">
</OBJECT><!-- 运行时设置的具有参数的 RDS.DataControl -->
<OBJECT classid="clsid:BD96C556-65A3-11D0-983A-00C04FC29E33"
   ID=ADC>
</OBJECT><Object CLASSID="clsid:AC05DC80-7DF1-11d0-839E-00A024A94B3A"
   CODEBASE="http://<%=Request.ServerVariables("SERVER_NAME")%>/MSADC/Samples/Sheridan.cab"
   ID=GRID1 
      datasrc=#ADC
      HEIGHT=125 
      WIDTH=495>
   <PARAM NAME="AllowAddNew" VALUE="TRUE">
   <PARAM NAME="AllowDelete" VALUE="TRUE">
   <PARAM NAME="AllowUpdate" VALUE="TRUE">
   <PARAM NAME="Caption" VALUE="RDSServer.DataFactory Run Time">
</OBJECT>
<HR>
<INPUT TYPE=BUTTON NAME="Run" VALUE="Run"><BR>
<H4>Click Run. The CreateObject Method of the RDS.DataSpace Object Creates an instance of the RDSServer.DataFactory. 
The Query Method of the RDSServer.DataFactory is used to bring back a Recordset. </H4>
</Center>
<Script Language="VBScript">
<!--
Dim ADF
Dim strServer
Dim strConnect
Dim strSQL
strServer = "http://<%=Request.ServerVariables("SERVER_NAME")%>"
strConnect = "dsn=ADCDemo;UID=ADCDemo;PWD=ADCDemo;"
strSQL = "Select * from Employee"Sub Run_OnClick()
   Dim objADORs      '创建 Recordset 对象
Set ADF = ADS1.CreateObject("RDSServer.DataFactory", strServer)            '获取 Recordset   
Set objADORs = ADF.Query(strConnect, strSQL)    
' 使用 RDS.DataControl 将 Recordset 绑定到网格敏感控件   ADC.SourceRecordset = objADORsEnd Sub
-->
</Script>

以下范例显示如何使用 CreateObject 方法创建自定义业务对象 VbBusObj.VbBusObjCls 的实例。该范例还使用 Active Server Pages 脚本标识 Web 服务器名。要查看完整的范例,请通过范例应用程序的选择器,在“客户端层”列中选择“VBScript in Internet Explorer”,并在“中间层”列中选择“自定义 Visual Basic 业务对象”。

Sub Window_OnLoad()
   strServer = "http://<%=Request.ServerVariables("SERVER_NAME")%>"
   Set BO = ADS1.CreateObject("VbBusObj.VbBusObjCls", strServer)
   txtConnect.Value = "dsn=pubs;uid=sa;pwd=;"
   txtGetRecordset.Value = "Select * From authors for Browse"
End Sub
www.holmesian.org