Refresh 方法范例 (VBScript)

以下范例举例说明如何在运行时设置必要的 RDS.DataControl 参数。使用 Refresh 方法检索 Recordset 的方式取决于 ExecuteOptionsFetchOptions 属性的设置。如要测试该范例,请剪切该代码并粘贴至规范的 HTML 文本的 <Body></Body> 标记之间,并将其命名为“ADCapi2.asp”。ASP 脚本将标识服务器。

<HTML>

<HEAD>

<TITLE>Refresh / ExecuteOptions</TITLE>

</HEAD>

<BODY>

<Center><H2>RDS API Code Examples </H2>

<HR>

<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="Remote Data Service Run Time">

</OBJECT>

<!-- 在设计时设置的不带参数的 RDS.DataControl -->

<OBJECT classid="clsid:BD96C556-65A3-11D0-983A-00C04FC29E33"

   ID=ADC>

   </OBJECT>

<HR>

<Input Size=70 Name="txtServer" Value="http://<%=Request.ServerVariables("SERVER_NAME")%>"><BR>

<Input Size=70 Name="txtConnect" Value = "dsn=ADCDemo;UID=ADCDemo;PWD=ADCDemo;"><BR>

<Input Size=70 Name="txtSQL" Value="Select * from Employee">

<BR>

Choose if you want the Recordset brought back Synchronously on the current calling thread or Asynchronously on another thread

<Input Type="Radio" Name="optExecuteOptions" Checked OnClick="SetExO('adcExecSync')">

<Input Type="Radio" Name="optExecuteOptions"  OnClick="SetExO('adcExecAsync')"><BR>

Fetch Up Front, Background Fetch with Blocking or Background Fetch without Blocking

<Input Type="Radio" Name="optFetchOptions"  OnClick="SetFO('adcFetchUpFront')">

<Input Type="Radio" Name="optFetchOptions" Checked OnClick="SetFO('adcFetchBackground')">

<Input Type="Radio" Name="optFetchOptions"  OnClick="SetFO('adcFetchAsync')">

<HR>

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

<H4>Fill Grid with these values or change them to see data from another ODBC data source on your server</H4>

</Center>

<Script Language="VBScript">

<!--

Dim EO          'ExecuteOptions

Dim FO         'FetchOptions

EO = "adcExecSync"   ' 默认值

FO = "adcFetchBackground"   ' 默认值

Sub SetExO(NewEO)

   EO = NewEO

End Sub

Sub SetFO(NewFO)

   FO = NewFO

End Sub

' 在运行时设置 RDS.DataControl 参数。

Sub Run_OnClick

   ADC.Server = txtServer.Value

   ADC.SQL = txtSQL.Value

   ADC.Connect = txtConnect.Value

If EO = "adcExecSync" Then      ' 选择 ExecuteOption

   ADC.ExecuteOptions = adcExecSync

      MsgBox "Recordset brought in on current calling thread Syncronously"

Else

   ADC.ExecuteOptions = adcExecAsync

         MsgBox "Recordset brought in on another thread Asyncronously"

End If

If FO = "adcFetchBackground" Then      ' 选择 FetchOption

   ADC.FetchOptions = adcFetchBackground

      MsgBox "Control goes back to user after first batch of records returned"

ElseIf FO = " adcFetchUpFront" Then

   ADC.FetchOptions = adcFetchUpFront

         MsgBox "All records returned before control goes back to user"

Else

   ADC.FetchOptions = adcFetchAsync

         MsgBox "Control goes back to user immediately"

End If

ADC.Refresh

End Sub

-->

</Script>

</BODY>

</HTML>