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 的類別。此程式碼會建立可為 @SalesPerson
參數指定值的 SyncParameter 物件。在應用程式中,此值可能來自登入 ID 或其他使用者輸入。若要在完整範例的內容中檢視程式碼,請參閱 HOW TO:篩選資料列和資料行。
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 命名空間