Bagikan melalui


Contoh Metode Objek DataSpace dan CreateObject (VBScript)

Penting

Dimulai dengan Windows 8 dan Windows Server 2012, komponen server RDS tidak lagi disertakan dalam sistem operasi Windows (lihat Windows 8 dan Windows Server 2012 Compatibility Cookbook untuk detail selengkapnya). Komponen klien RDS akan dihapus di versi Windows yang akan datang. Hindari menggunakan fitur ini dalam pekerjaan pengembangan baru, dan rencanakan untuk memodifikasi aplikasi yang saat ini menggunakan fitur ini. Aplikasi yang menggunakan RDS harus bermigrasi ke WCF Data Service.

Contoh berikut menunjukkan cara menggunakan metode CreateObject dari RDS. DataSpace dengan objek bisnis default, RDSServer.DataFactory. Untuk menguji contoh ini, potong dan tempel kode ini antara< Isi >dan tag </Body> dalam dokumen HTML normal dan beri nama DataSpaceVBS.asp. Skrip ASP akan mengidentifikasi server Anda.

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

Contoh berikut menunjukkan cara menggunakan metode CreateObject untuk membuat instans objek bisnis kustom, VbBusObj.VbBusObjCls. Ini juga menggunakan pembuatan skrip Halaman Server Aktif untuk mengidentifikasi nama server Web.

Untuk melihat contoh lengkapnya, buka pemilih aplikasi sampel. Di kolom Tingkat Klien, pilih VBScript di Internet Explorer. Di kolom Tingkat Tengah, pilih Objek Bisnis Visual Basic Kustom.

Nota

Jika Anda menyambungkan ke penyedia sumber data yang mendukung autentikasi Windows, Anda harus menentukan Trusted_Connection=yes atau Integrated Security = SSPI alih-alih ID pengguna dan informasi kata sandi dalam string koneksi.

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  

Lihat Juga

Metode CreateObject (RDS)
DataSpace Object (RDS)