共用方式為


DataSpace 物件和 CreateObject 方法範例 (VBScript)

重要

從 Windows 8 和 Windows Server 2012 開始,RDS 伺服器元件已不再包含在 Windows 作業系統中(如需詳細資訊,請參閱 Windows 8 和 Windows Server 2012 兼容性 Cookbook)。 RDS 用戶端元件將在未來的 Windows 版本中移除。 請避免在新的開發工作中使用此功能,並計劃修改目前使用此功能的應用程式。 使用 RDS 的應用程式應該移至 WCF Data Service

下列範例示範如何使用 RDS 的 CreateObject 方法。DataSpace 預設商務物件,RDSServer.DataFactory。 若要測試此範例,請將此程式代碼剪下並貼到一般 HTML 檔中的 <Body> 和 </Body> 標籤,並將其命名為 DataSpaceVBS.asp。 ASP 文稿會識別您的伺服器。

<!-- BeginDataSpaceVBS -->  
<html>  
<head>  
<!--use the following META tag instead of adovbs.inc-->  
<!--METADATA TYPE="typelib" uuid="00000205-0000-0010-8000-00AA006D2EA4" -->  
    <meta name="VI60_DefaultClientScript"  content=VBScript>  
    <meta name="GENERATOR" content="Microsoft Visual Studio 6.0">  
    <title>DataSpace Object and CreateObject Method Example (VBScript)</title>  
<style>  
<!--  
body {  
   font-family: 'Verdana','Arial','Helvetica',sans-serif;  
   BACKGROUND-COLOR:white;  
   COLOR:black;  
    }  
.thead {  
   background-color: #008080;   
   font-family: 'Verdana','Arial','Helvetica',sans-serif;   
   font-size: x-small;  
   color: white;  
   }  
.thead2 {  
   background-color: #800000;   
   font-family: 'Verdana','Arial','Helvetica',sans-serif;   
   font-size: x-small;  
   color: white;  
   }  
.tbody {   
   text-align: center;  
   background-color: #f7efde;  
   font-family: 'Verdana','Arial','Helvetica',sans-serif;   
   font-size: x-small;  
    }  
-->  
</style>  
</head>  
  
<body>  
<h1>DataSpace Object and CreateObject Method Example (VBScript)</h1>  
  
<H2>RDS API Code Examples</H2>  
<HR>  
<H3>Using Query Method of RDSServer.DataFactory</H3>  
  
<!-- RDS.DataSpace  ID rdsDS-->  
<OBJECT ID="rdsDS" 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 <i>CreateObject</i> Method of the RDS.DataSpace Object Creates an instance of the RDSServer.DataFactory.  
The <i>Query</i> Method of the RDSServer.DataFactory is used to bring back a Recordset.</H4>  
  
<Script Language="VBScript">  
  
    Dim rdsDF  
    Dim strServer  
    Dim strCnxn  
    Dim strSQL  
  
    strServer = "https://<%=Request.ServerVariables("SERVER_NAME")%>"  
    strCnxn = "Provider='sqloledb';Data Source=" & _  
            "<%=Request.ServerVariables("SERVER_NAME")%>" & ";" & _  
            "Integrated Security='SSPI';Initial Catalog='Northwind';"  
    strSQL = "Select FirstName, LastName from Employees"  
  
    Sub Run_OnClick()  
  
       Dim rs        
        ' Create Data Factory  
       Set rdsDF = rdsDS.CreateObject("RDSServer.DataFactory", strServer)  
        'Get Recordset    
       Set rs = rdsDF.Query(strCnxn, strSQL)     
       ' Use  RDS.DataControl to bind Recordset to data-aware Table above  
       RDS.SourceRecordset = rs  
  
    End Sub  
</Script>  
  
</body>  
</html>  
<!-- EndDataSpaceVBS -->  

下列範例示範如何使用 CreateObject 方法來建立自定義商業對象的實例 VbBusObj.VbBusObjCls。 它也會使用 Active Server Pages 腳本來識別網頁伺服器名稱。

若要查看完整的範例,請開啟範例應用程式選取器。 在 [用戶端層] 數據行中,選取 Internet Explorer VBScript。 在 [中介層] 資料行中,選取 [自定義 Visual Basic 商務物件]

注意

如果您要連線到支援 Windows 驗證的數據源提供者,您應該指定 Trusted_Connection=yesIntegrated Security = SSPI,而不是連接字元串中的使用者識別符和密碼資訊。

Sub Window_OnLoad()  
   strServer = "https://<%=Request.ServerVariables("SERVER_NAME")%>"  
   Set BO = ADS1.CreateObject("VbBusObj.VbBusObjCls", strServer)  
   txtConnect.Value = "dsn=Pubs;uid=MyUserID;pwd=<password>;"  
   txtGetRecordset.Value = "Select * From authors for Browse"  
End Sub  

另請參閱

CreateObject 方法 (RDS)
DataSpace 物件 (RDS)