Share via


SyncParameter Class

Encapsulates information sent from the client to the server.

Inheritance Hierarchy

System.Object
  Microsoft.Synchronization.Data.SyncParameter

Namespace:  Microsoft.Synchronization.Data
Assembly:  Microsoft.Synchronization.Data (in Microsoft.Synchronization.Data.dll)

Syntax

'Declaration
<SerializableAttribute> _
Public Class SyncParameter
'Usage
Dim instance As SyncParameter
[SerializableAttribute]
public class SyncParameter
[SerializableAttribute]
public ref class SyncParameter
[<SerializableAttribute>]
type SyncParameter =  class end
public class SyncParameter

The SyncParameter type exposes the following members.

Constructors

  Name Description
Public method SyncParameter() Initializes a new instance of the SyncParameter class by using default values.
Public method SyncParameter(String, Object) Initializes a new instance of the SyncParameter class by using name and value parameters.

Top

Properties

  Name Description
Public property Name Gets or sets the name of the parameter.
Public property Value Gets or sets the value of the parameter.

Top

Methods

  Name Description
Public method Equals Determines whether a SyncParameter object is equal to the specified object. (Overrides Object.Equals(Object).)
Protected method Finalize (Inherited from Object.)
Public method GetHashCode Serves as a hash function for a SyncParameter. This is suitable for use in hashing algorithms and data structures such as a hash table. (Overrides Object.GetHashCode().)
Public method GetType (Inherited from Object.)
Protected method MemberwiseClone (Inherited from Object.)
Public method ToString Returns a string that represents the SyncParameter object. (Overrides Object.ToString().)

Top

Operators

  Name Description
Public operatorStatic member Equality Determines whether the two specified SyncParameter objects are equal.
Public operatorStatic member Inequality Determines whether the two specified SyncParameter objects are not equal.

Top

Remarks

Synchronization parameters are typically used to pass filtering information to the synchronization agent. These parameters are then used in commands for the synchronization adapter.

Examples

The following code example is from a class that derives from SyncAgent. This code creates a SyncParameter object that specifies a value for the @SalesPerson parameter. In an application, this value might come from a login ID or other user input. To view code in the context of a complete example, see How to: Filter Rows and Columns.

this.Configuration.SyncParameters.Add(
    new SyncParameter("@SalesPerson", "Brenda Diaz"));
Me.Configuration.SyncParameters.Add(New SyncParameter("@SalesPerson", "Brenda Diaz"))

The following code example is from a class that derives from DbServerSyncProvider. This code specifies which inserted columns and rows to download for the Customer table. You can hardcode a value for SalesPerson. However, it is more common to use a parameter that has a value that can change, as shown in the example. The example passes the filter parameter together with the other parameters that are required to download incremental inserts.

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

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

Microsoft.Synchronization.Data Namespace