SyncConfiguration.SyncParameters 属性
获取在服务器上可作为会话变量使用的 SyncParameter 对象的 SyncParameterCollection。
命名空间: Microsoft.Synchronization.Data
程序集: Microsoft.Synchronization.Data(在 microsoft.synchronization.data.dll 中)
语法
声明
Public ReadOnly Property SyncParameters As SyncParameterCollection
用法
Dim instance As SyncConfiguration
Dim value As SyncParameterCollection
value = instance.SyncParameters
public SyncParameterCollection SyncParameters { get; }
public:
property SyncParameterCollection^ SyncParameters {
SyncParameterCollection^ get ();
}
/** @property */
public SyncParameterCollection get_SyncParameters ()
public function get SyncParameters () : SyncParameterCollection
属性值
SyncParameter 对象的 SyncParameterCollection。
备注
同步参数通常用于将筛选信息传递给同步代理。然后在同步适配器的命令中使用这些参数。
示例
下面的代码示例摘自从 SyncAgent 派生的类。此代码创建一个 SyncParameter 对象,该对象指定 @SalesPerson
参数的值。在应用程序中,此值可能来自登录 ID 或其他用户输入。若要在完整示例上下文中查看代码,请参见如何筛选行和列。
this.Configuration.SyncParameters.Add(
new SyncParameter("@SalesPerson", "Brenda Diaz"));
Me.Configuration.SyncParameters.Add(New SyncParameter("@SalesPerson", "Brenda Diaz"))
下面的代码示例摘自从 DbServerSyncProvider 派生的类。此代码指定要下载 Customer
表的哪些插入的列和行。可以对 SalesPerson
的值进行硬编码。但是,更常见的是使用一个可以变更值的参数,如示例中所示。示例将筛选参数与下载增量插入所需的其他参数一起传递。
SqlCommand customerIncrInserts = new SqlCommand();
customerIncrInserts.CommandText =
"SELECT CustomerId, CustomerName, CustomerType " +
"FROM Sales.Customer " +
"WHERE SalesPerson = @SalesPerson " +
"AND (InsertTimestamp > @sync_last_received_anchor " +
"AND InsertTimestamp <= @sync_new_received_anchor " +
"AND InsertId <> @sync_client_id)";
customerIncrInserts.Parameters.Add("@SalesPerson", SqlDbType.NVarChar);
customerIncrInserts.Parameters.Add("@" + SyncSession.SyncLastReceivedAnchor, SqlDbType.Timestamp);
customerIncrInserts.Parameters.Add("@" + SyncSession.SyncNewReceivedAnchor, SqlDbType.Timestamp);
customerIncrInserts.Parameters.Add("@" + SyncSession.SyncClientId, SqlDbType.UniqueIdentifier);
customerIncrInserts.Connection = serverConn;
customerSyncAdapter.SelectIncrementalInsertsCommand = customerIncrInserts;
Dim customerIncrInserts As New SqlCommand()
With customerIncrInserts
.CommandText = _
"SELECT CustomerId, CustomerName, CustomerType " _
& "FROM Sales.Customer " _
& "WHERE SalesPerson = @SalesPerson " _
& "AND (InsertTimestamp > @sync_last_received_anchor " _
& "AND InsertTimestamp <= @sync_new_received_anchor " _
& "AND InsertId <> @sync_client_id)"
.Parameters.Add("@SalesPerson", SqlDbType.NVarChar)
.Parameters.Add("@" + SyncSession.SyncLastReceivedAnchor, SqlDbType.Timestamp)
.Parameters.Add("@" + SyncSession.SyncNewReceivedAnchor, SqlDbType.Timestamp)
.Parameters.Add("@" + SyncSession.SyncClientId, SqlDbType.UniqueIdentifier)
.Connection = serverConn
End With
customerSyncAdapter.SelectIncrementalInsertsCommand = customerIncrInserts
请参阅
参考
SyncConfiguration 类
SyncConfiguration 成员
Microsoft.Synchronization.Data 命名空间