SyncAdapter::InsertCommand Property
Gets or sets the query or stored procedure that is used to insert data into the server database.
Assembly: Microsoft.Synchronization.Data.Server (in Microsoft.Synchronization.Data.Server.dll)
public: property IDbCommand^ InsertCommand { IDbCommand^ get (); void set (IDbCommand^ value); }
Property Value
Type: System.Data::IDbCommandAn IDbCommand object that contains a query or stored procedure.
Synchronization adapter commands enable you to specify the queries and stored procedures that are used to select from and apply changes to the server database. For more information, see How to: Specify Snapshot, Download, Upload, and Bidirectional Synchronization. Each command uses session variables that enable you to pass values during synchronization. These variables are specified like other parameters to queries or stored procedures in ADO.NET commands. For more information, see How to: Use Session Variables.
The following code example creates a command that inserts rows into the Customer table in bidirectional and upload-only synchronization scenarios. The command is a stored procedure that is defined in Setup Scripts for Database Provider How-to Topics. To view this code in the context of a complete example, see How to: Handle Data Conflicts and Errors.
SqlCommand customerInserts = new SqlCommand(); customerInserts.CommandType = CommandType.StoredProcedure; customerInserts.CommandText = "usp_CustomerApplyInsert"; customerInserts.Parameters.Add("@" + SyncSession.SyncClientId, SqlDbType.UniqueIdentifier); customerInserts.Parameters.Add("@" + SyncSession.SyncForceWrite, SqlDbType.Bit); customerInserts.Parameters.Add("@" + SyncSession.SyncRowCount, SqlDbType.Int).Direction = ParameterDirection.Output; customerInserts.Parameters.Add("@CustomerId", SqlDbType.UniqueIdentifier); customerInserts.Parameters.Add("@CustomerName", SqlDbType.NVarChar); customerInserts.Parameters.Add("@SalesPerson", SqlDbType.NVarChar); customerInserts.Parameters.Add("@CustomerType", SqlDbType.NVarChar); customerInserts.Connection = serverConn; customerSyncAdapter.InsertCommand = customerInserts;
Dim customerInserts As New SqlCommand() customerInserts.CommandType = CommandType.StoredProcedure customerInserts.CommandText = "usp_CustomerApplyInsert" customerInserts.Parameters.Add("@" + SyncSession.SyncClientId, SqlDbType.UniqueIdentifier) customerInserts.Parameters.Add("@" + SyncSession.SyncForceWrite, SqlDbType.Bit) customerInserts.Parameters.Add("@" + SyncSession.SyncRowCount, SqlDbType.Int).Direction = ParameterDirection.Output customerInserts.Parameters.Add("@CustomerId", SqlDbType.UniqueIdentifier) customerInserts.Parameters.Add("@CustomerName", SqlDbType.NVarChar) customerInserts.Parameters.Add("@SalesPerson", SqlDbType.NVarChar) customerInserts.Parameters.Add("@CustomerType", SqlDbType.NVarChar) customerInserts.Connection = serverConn customerSyncAdapter.InsertCommand = customerInserts