DataSpace Object and CreateObject Method Example (VBScript)

Microsoft ActiveX Data Objects (ADO)

DataSpace Object and CreateObject Method Example (VBScript)

The following example shows how to use the CreateObject method of the RDS.DataSpace with the default business object, RDSServer.DataFactory. To test this example, cut and paste this code between the <Body></Body> tags in a normal HTML document and name it ADCapi8.asp. ASP script will identify your server.

<H2>RDS API Code Examples</H2>
<HR>
<H3>Using Query Method of RDSServer.DataFactory</H3>

<!-- RDS.DataSpace  ID RDS1-->
<OBJECT ID="RDS1" WIDTH=1 HEIGHT=1
CLASSID="CLSID:BD96C556-65A3-11D0-983A-00C04FC29E36">
</OBJECT>

<!-- RDS.DataControl with parameters set at run time -->
<OBJECT classid="clsid:BD96C556-65A3-11D0-983A-00C04FC29E33"
    ID=RDS WIDTH=1 HEIGHT=1>
</OBJECT>

<TABLE DATASRC=#RDS>
<TBODY>
  <TR>
    <TD><SPAN DATAFLD="FirstName"></SPAN></TD>
    <TD><SPAN DATAFLD="LastName"></SPAN></TD>
  </TR>
</TBODY>
</TABLE>

<HR>
<INPUT TYPE=BUTTON NAME="Run" VALUE="Run">

<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>

<Script Language="VBScript">
<!--
Dim DF
Dim strServer
Dim strConnect
Dim strSQL
strServer = "http://<%=Request.ServerVariables("SERVER_NAME")%>"
strConnect = "Provider=SQLOLEDB;User Id=rdsdemo;Password=rdsdemo;" & _
                  "Initial Catalog=AddrBookDB;Data Source=MyServer;"
strSQL = "Select * from Employee"

Sub Run_OnClick()
    Dim objADORs      'Create Recordset Object
    Set DF = RDS1.CreateObject("RDSServer.DataFactory", strServer)      'Get Recordset  
    Set objADORs = DF.Query(strConnect, strSQL)   
    ' Use  RDS.DataControl to bind Recordset to Data
    ' Aware Grid Control

    RDS.SourceRecordset = objADORs

End Sub
-->
</Script>

The following example shows how to use the CreateObject method to create an instance of a custom business object, VbBusObj.VbBusObjCls. It also uses the Active Server Pages scripting to identify the Web server name. To see the complete example, choose "VBScript in Internet Explorer" in the Client Tier column and "Custom Visual Basic Business Object" in the Middle Tier column from the sample applications selector.

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