Share via


SyncParameter 类

封装从客户端发送至服务器的信息。

命名空间:  Microsoft.Synchronization.Data
程序集:  Microsoft.Synchronization.Data(在 Microsoft.Synchronization.Data.dll 中)

语法

声明
<SerializableAttribute> _
Public Class SyncParameter
用法
Dim instance As SyncParameter
[SerializableAttribute]
public class SyncParameter
[SerializableAttribute]
public ref class SyncParameter
[<SerializableAttribute>]
type SyncParameter =  class end
public class SyncParameter

注释

同步参数通常用于将筛选信息传递给同步代理。然后在同步适配器的命令中使用这些参数。

示例

下面的代码示例摘自从 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

继承层次结构

System. . :: . .Object
  Microsoft.Synchronization.Data..::..SyncParameter

线程安全

此类型的所有公共成员static(在 Visual Basic 中为 Shared) 都是线程安全的。不保证所有实例成员都是线程安全的。

请参阅

参考

SyncParameter 成员

Microsoft.Synchronization.Data 命名空间