Server 屬性範例 (VBScript)
重要
從 Windows 8 和 Windows Server 2012 開始,Windows 作業系統中不再包含 RDS 伺服器元件 (請參閱 Windows 8 和 Windows Server 2012 相容性操作手冊以取得詳細資訊)。 未來的 Windows 版本將移除 RDS 用戶端元件。 請避免在新的開發工作中使用這項功能,並規劃修改目前使用這項功能的應用程式。 使用 RDS 的應用程式應移轉至 WCF 資料服務。
下列程式碼顯示如何使用 SQLOLEDB 提供者,在設計階段設定 RDS.DataControl 參數,並將其繫結至資料感知控制項。 將此程式碼剪貼至一般 ASP 文件中,並將其命名為 ServerDesignVBS.asp。 ASP 指令碼會識別您的伺服器。
<!-- BeginServerDesignVBS -->
<%@ Language=VBScript %>
<html>
<head>
<meta name="VI60_DefaultClientScript" content=VBScript>
<meta name="GENERATOR" content="Microsoft Visual Studio 6.0">
<title>Server Property 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>Server Property Example (VBScript)</h1>
<TABLE DATASRC=#RDS>
<TR>
<TD> <SPAN DATAFLD="FirstName"></SPAN> </TD>
<TD> <SPAN DATAFLD="LastName"></SPAN> </TD>
<TD> <SPAN DATAFLD="Title"></SPAN> </TD>
<TD> <SPAN DATAFLD="Type"></SPAN> </TD>
<TD> <SPAN DATAFLD="Email"></SPAN> </TD>
</TR>
</TABLE>
<!-- Remote Data Service with Parameters set at Design Time -->
<OBJECT classid="clsid:BD96C556-65A3-11D0-983A-00C04FC29E33"
ID=RDS HEIGHT=1 WIDTH=1>
<PARAM NAME="SQL" VALUE="Select * from Employees">
<PARAM NAME="SERVER" VALUE="https://<%=Request.ServerVariables("SERVER_NAME")%>">
<PARAM NAME="CONNECT" VALUE="Provider='sqloledb';Integrated Security='SSPI';Initial Catalog='Northwind'">
</OBJECT>
</body>
</html>
<!-- EndServerDesignVBS -->
下列範例顯示如何在執行階段上設定 RDS.DataControl 的必要參數。 若要測試此範例,請將下列程式碼剪貼至一般 ASP 文件中,並將其命名為 ServerRuntimeVBS.asp。 ASP 指令碼會識別您的伺服器。
<!-- BeginServerRuntimeVBS -->
<%@ Language=VBScript %>
<html>
<head>
<meta name="VI60_DefaultClientScript" content=VBScript>
<meta name="GENERATOR" content="Microsoft Visual Studio 6.0">
<title>Server Property 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>Server Property Example (VBScript)</h1>
<H2>RDS API Code Examples</H2>
<H3>Remote Data Service Server Property Set at Run Time</H3>
<!-- RDS.DataControl with no parameters set at design time -->
<OBJECT classid="clsid:BD96C556-65A3-11D0-983A-00C04FC29E33"
ID=RDC HEIGHT=1 WIDTH=1>
</OBJECT>
<TABLE DATASRC=#RDC>
<TR>
<TD> <SPAN DATAFLD="FirstName"></SPAN> </TD>
<TD> <SPAN DATAFLD="LastName"></SPAN> </TD>
<TD> <SPAN DATAFLD="Title"></SPAN> </TD>
<TD> <SPAN DATAFLD="Type"></SPAN> </TD>
<TD> <SPAN DATAFLD="Email"></SPAN> </TD>
</TR>
</TABLE>
<HR>
<Input Size=70 Name="txtServer" Value="HTTP://<%= Request.ServerVariables("SERVER_NAME")%>">
<BR>
<Input Size=70 Name="txtConnect" Value="Provider='sqloledb';Integrated Security='SSPI';Initial Catalog='Northwind'">
<BR>
<Input Size=70 Name="txtSQL" Value="Select * from Employees">
<HR>
<INPUT TYPE=BUTTON NAME="Run" VALUE="Run"><BR>
<Script Language="VBScript">
<!--
' Set parameters of RDS.DataControl at Run Time
Sub Run_OnClick
RDC.Server = txtServer.Value
RDC.SQL = txtSQL.Value
RDC.Connect = txtConnect.Value
RDC.Refresh
End Sub
-->
</Script>
</body>
</html>
<!-- EndServerRuntimeVBS -->