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
/** @attribute SerializableAttribute() */
public class SyncParameter
SerializableAttribute
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
线程安全
此类型的所有公共静态(在 Visual Basic 中共享 )成员都是线程安全的。不保证任何实例成员的线程安全。