共用方式為


SyncAdapter.InsertCommand 屬性

取得或設定用來將資料插入伺服器資料庫的查詢或預存程序。

命名空間: Microsoft.Synchronization.Data.Server
組件: Microsoft.Synchronization.Data.Server (在 microsoft.synchronization.data.server.dll)

語法

'宣告
Public Property InsertCommand As IDbCommand
'用途
Dim instance As SyncAdapter
Dim value As IDbCommand

value = instance.InsertCommand

instance.InsertCommand = value
public IDbCommand InsertCommand { get; set; }
public:
property IDbCommand^ InsertCommand {
    IDbCommand^ get ();
    void set (IDbCommand^ value);
}
/** @property */
public IDbCommand get_InsertCommand ()

/** @property */
public void set_InsertCommand (IDbCommand value)
public function get InsertCommand () : IDbCommand

public function set InsertCommand (value : IDbCommand)

屬性值

包含查詢或預存程序的 IDbCommand 物件。

備註

同步處理配接器命令可讓您指定,用來從伺服器資料庫選取及套用變更的查詢和預存程序。如需詳細資訊,請參閱 HOW TO:指定快照集、下載、上傳及雙向同步處理。每一個命令都會使用同步處理期間可讓您傳遞值的工作階段變數。指定這些變數與其他參數的指定方式一樣,都是在 ADO.NET 命令中指定到查詢或預存程序中。如需詳細資訊,請參閱 HOW TO:使用工作階段變數

範例

下列程式碼範例會在雙向及僅供上傳的同步處理案例中,建立可在 Customer 資料表中插入資料列的命令。此命令是資料庫提供者的安裝指令碼 HOW-TO 主題中所定義的預存程序。若要在完整範例的內容中檢視這段程式碼,請參閱 HOW TO:處理資料衝突和錯誤

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

請參閱

參考

SyncAdapter 類別
SyncAdapter 成員
Microsoft.Synchronization.Data.Server 命名空間