共用方式為


Handler 属性範例 (VB)

重要

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

此範例示範 RDS DataControl 物件 Handler 屬性。 (如需詳細資訊,請參閱 DataFactory 自定義

假設參數檔案中的下列區段 Msdfmap.ini位於伺服器上:

[connect AuthorDataBase]  
Access=ReadWrite  
Connect="DSN=Pubs"  
[sql AuthorById]  
SQL="SELECT * FROM Authors WHERE au_id = ?"  

您的程序代碼如下所示。 指派給 SQL 屬性的命令會比對 AuthorById 識別符,並擷取作者 Michael O'Leary 的數據列。 DataControl 物件 Recordset 屬性會指派給中斷連線的 Recordset Recordset 物件,以方便撰寫程式代碼。

'BeginHandlerVB  
Public Sub Main()  
    On Error GoTo ErrorHandler  
  
    Dim dc As New DataControl  
    Dim rst As ADODB.Recordset  
  
    dc.Handler = "MSDFMAP.Handler"  
    dc.ExecuteOptions = 1  
    dc.FetchOptions = 1  
    dc.Server = "https://MyServer"  
    dc.Connect = "Data Source=AuthorDataBase"  
    dc.SQL = "AuthorById('267-41-2394')"  
    dc.Refresh                  'Retrieve the record  
    Set rst = dc.Recordset      'Use another Recordset as a convenience  
    Debug.Print "Author is '" & rst!au_fname & " " & rst!au_lname & "'"  
  
    ' clean up  
    If rst.State = adStateOpen Then rst.Close  
    Set rst = Nothing  
    Set dc = Nothing  
    Exit Sub  
  
ErrorHandler:  
    ' clean up  
    If Not rst Is Nothing Then  
        If rst.State = adStateOpen Then rst.Close  
    End If  
    Set rst = Nothing  
    Set dc = Nothing  
  
    If Err <> 0 Then  
        MsgBox Err.Source & "-->" & Err.Description, , "Error"  
    End If  
End Sub  
'EndHandlerVB  

另請參閱

DataControl 物件 (RDS)
Handler 屬性 (RDS)