Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 11.0.1 (中文) » MobiLink - 服务器管理 » MobiLink 服务器 API » 使用 .NET 编写同步脚本 » 用于 .NET 参考的 MobiLink 服务器 API


DownloadTableData 接口

interface DownloadTableData




CREATE TABLE remoteOrders (
    pk INT NOT NULL,
    col1 VARCHAR(200),
    PRIMARY KEY (pk)

以下示例使用 DownloadData.GetDownloadTableByName 方法返回表示 remoteOrders 表的 DownloadTableData 实例。

// The method used for the handle_DownloadData event
public void HandleDownload() {
    // _cc is a DBConnectionContext instance.

    // Get the DownloadData for the current synchronization.
    DownloadData my_dd = _cc.GetDownloadData();
    // Get the DownloadTableData for the remoteOrders table.
    DownloadTableData td = my_dd.GetDownloadTableByName("remoteOrders");

    // User defined-methods to set download operations.

    // ... 

在本例中,SetDownloadInserts 方法使用 DownloadTableData.GetUpsertCommand 为您想要插入或更新的行获取命令。IDbCommand 将会保存一些参数,这些参数将会被设置为您要插入到远程数据库中的值。

void SetDownloadInserts(DownloadTableData td) { 
    IDbCommand  upsert_cmd = td.GetUpsertCommand();
    IDataParameterCollection parameters = upsert_cmd.Parameters;
    // The following method calls are the same as the following SQL statement:
    // INSERT INTO remoteOrders(pk, col1) values(2300, "truck");
    ((IDataParameter) (parameters[0])).Value = (Int32) 2300;
    ((IDataParameter) (parameters[1])).Value = (String) "truck";

    if (upsert_cmd.ExecuteNonQuery() > 0) {
        // Insert was not filtered.
    else {
        // Insert was filtered because it was uploaded
        // in the same synchronization.

SetDownloadDeletes 方法使用 DownloadTableData.GetDeleteCommand 为您想要删除的行获取命令。

void SetDownloadDeletes(DownloadTableData td) { 
    IDbCommand  delete_cmd = t2_download_dd.GetDeleteCommand();

    // The following method calls are the same as the following SQL statement:
    // DELETE FROM remoteOrders  where pk = 2300;
    IDataParameterCollection parameters = delete_cmd.Parameters;
    ((IDataParameter) (parameters[0])).Value = (Int32) 2300;

GetDeleteCommand 方法
GetLastDownloadTime 方法
GetName 方法
GetSchemaTable 方法
GetUpsertCommand 方法