使用名稱和值參數初始化 SyncParameter 類別的新執行個體。
命名空間: Microsoft.Synchronization.Data
組件: Microsoft.Synchronization.Data (在 microsoft.synchronization.data.dll)
語法
'宣告
Public Sub New ( _
name As String, _
value As Object _
)
'用途
Dim name As String
Dim value As Object
Dim instance As New SyncParameter(name, value)
public SyncParameter (
string name,
Object value
)
public:
SyncParameter (
String^ name,
Object^ value
)
public SyncParameter (
String name,
Object value
)
public function SyncParameter (
name : String,
value : Object
)
參數
- name
此參數的名稱。
- value
此參數的值。
備註
同步處理參數通常是用來將篩選資訊傳遞給同步代理程式。然後這些參數會在同步處理配接器的命令中使用。
範例
下列程式碼範例來自衍生自 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
請參閱
參考
SyncParameter 類別
SyncParameter 成員
Microsoft.Synchronization.Data 命名空間