步骤 6:将更改发送到服务器(RDS 教程)

如果编辑 Recordset 对象,则可以将任何更改(即添加、更改或删除的行)发送回服务器。

注意

可以使用 ADO 对象和 Microsoft OLE DB 远程处理提供程序隐式调用 RDS 的默认行为。 查询可以返回 Recordset,编辑过的 Recordset可以更新数据源。 本教程不会使用 ADO 对象来使用 RDS,但如果调用的话,操作会像下面这样:

Dim rs as New ADODB.Recordset  
rs. "SELECT * FROM Authors","=MS Remote;=Pubs;" & _  
=https://yourServer;=SQLOLEDB;"  
...              ' Edit the Recordset.  
rs.   ' The equivalent of   
...  

第 A 部分 假设在本例中,你只使用了 RDS。DataControlRecordset 对象现在与 RDS 相关联。DataControl。 如果 服务器 属性和 Connect 属性仍然设置,那么 SubmitChanges 方法将使用对 Recordset 对象所做的任何更改更新数据源。

Sub RDSTutorial6A()  
Dim DC as New RDS.DataControl  
Dim RS as ADODB.Recordset  
DC. = "https://yourServer"  
DC. = "DSN=Pubs"  
DC. = "SELECT * FROM Authors"  
DC.  
...  
Set RS = DC.  
   ' Edit the Recordset.  
...  
DC.  
...  

第 B 部分 或者,可以使用 RDSServer.DataFactory 对象更新服务器,并指定连接和 Recordset 对象。

Sub RDSTutorial6B()  
Dim DS As New RDS.DataSpace  
Dim RS As ADODB.Recordset  
Dim DC As New RDS.DataControl  
Dim DF As Object  
Dim blnStatus As Boolean  
Set DF = DS.("RDSServer.DataFactory", "https://yourServer")  
Set RS = DF. ("DSN=Pubs", "SELECT * FROM Authors")  
DC. = RS    ' Visual controls can now bind to DC.  
    ' Edit the Recordset.  
blnStatus = DF."DSN=Pubs", RS  
End Sub  

这是本教程的结尾。

重要

从 Windows 8 和 Windows Server 2012 开始,RDS 服务器组件不再包含在 Windows 操作系统中(有关详细信息,请参阅 Windows 8 和 Windows Server 2012 兼容性指南)。 RDS 客户端组件将在将来的 Windows 版本中删除。 避免在新开发工作中使用此功能,并计划修改当前使用此功能的应用程序。 使用 RDS 的应用程序应迁移到 WCF 数据服务

另请参阅

Microsoft OLE DB 远程处理提供程序(ADO 服务提供程序)
RDS 教程
RDS 教程 (VBScript)