#眉標=Visual Studio 2008 #副標=體驗新一代整合開發環境(4) #大標= ADO.NET最新資料庫同步服務(下) #作者=文/圖 王寧疆 ===<反灰>============= using Microsoft.Synchronization.Data; ================ ===<反灰>============= NorthwindSyncAgent syncAgent = new NorthwindSyncAgent(); //建立Sync Agent SyncStatistics syncStats = syncAgent.Synchronize(); //呼叫Synchronize方法執行資料庫同步處理的動作 ================ ===<反灰>============= private void Form1_Load(object sender, EventArgs e) { NorthwindSyncAgent syncAgent = new NorthwindSyncAgent(); Microsoft.Synchronization.Data.SyncStatistics syncStats = syncAgent.Synchronize(); // TODO:這行程式碼會將資料載入 'northwindDataSet.Orders' 資料表。你可以視需要進行移動或移除。 this.ordersTableAdapter.Fill(this.northwindDataSet.Orders); // TODO:這行程式碼會將資料載入'northwindDataSet.Customers'資料表。你可以視需要進行移動或移除。 this.customersTableAdapter.Fill(this.northwindDataSet.Customers); } ================ ============= private void toolStripButton1_Click(object sender, EventArgs e) { NorthwindSyncAgent SyncAgent =new NorthwindSyncAgent(); // 建立SyncAgent   NorthwindServerSyncProvider ServerSyncProvider =    new NorthwindServerSyncProvider(); //建立ServerSyncProvider   SyncAgent.RemoteProvider = ServerSyncProvider; //設定SyncAgent的RemoteProvider屬性 NorthwindClientSyncProvider ClientSyncProvider = new NorthwindClientSyncProvider(); //建立ClientSyncProvider   SyncAgent.LocalProvider = ClientSyncProvider; //設定SyncAgent的LocalProvider屬性   SyncAgent.Customers.SyncDirection =    SyncDirection.Bidirectional; //設定Customers資料表中的記錄要進行雙向同步   SyncAgent.Orders.SyncDirection = SyncDirection.Bidirectional; //設定Orders資料表中的記錄要進行雙向同步      SyncGroup sgOrders =new SyncGroup("Northwind"); //建立SyncGroup類別的物件 SyncAgent.Customers.SyncGroup = sgOrders; //將Customers資料表加入SyncGroup類別的物件 SyncAgent.Orders.SyncGroup = sgOrders; //將Orders資料表加入SyncGroup類別的物件 SyncStatistics syncStats = SyncAgent.Synchronize(); //執行雙向資料同步   this.customersTableAdapter.Fill( this.northwindDataSet.Customers); //載入同步處理後的記錄到DataSet中的Customers資料表 this.ordersTableAdapter.Fill( this.northwindDataSet.Orders); //載入同步處理後的記錄到DataSet中的Orders資料表 } ================