Welcome to WindowsClient.net | Sign in | Join

Ken Tucker

Visual Basic MVP

Sponsors





  • advertise here

Sync Services Part 1

In this post we will create a local cache of the Northwind database.  To start with lets create a new visual basic windows forms project in Visual Studio 2008.  From the project menu select add a new item and select a new local database cache and name it northwind.

 

image

 

In the server connect select a connection to the northwind database.

 

Press the add button and select the product table.  Press OK to close the dialog.  Go ahead and create a table adapter for the product table.  The drag the products table on to the form from the data source window.  Add a button to the binding navigator and set its text to Sync and change the display style to Text.

 

In the button you added to the toolbar add this code

 

Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click

       ' Update the database

        Me.ProductsBindingSource.EndEdit()         Me.TableAdapterManager.UpdateAll(Me.NorthwindDataSet)

        ' Call SyncAgent.Synchronize() to initiate the synchronization process.

        ' Synchronization only updates the local database, not your project’s data source.

        Dim syncAgent As ProductsSyncAgent = New ProductsSyncAgent()         Dim syncStats As Microsoft.Synchronization.Data.SyncStatistics = syncAgent.Synchronize()

       ' Reload the data source from the local database

        Me.ProductsTableAdapter.Fill(Me.NorthwindDataSet.Products)

End Sub

Run the app and Open up the Sql Server Management Studio Express.  Make some changes in the Northwind database's Product table and Press the sync button.  

 

Notice the changes you made to the Products table show up in the datagridview.  The changes are also saved in the local sqlce database.



Comments

No Comments

Leave a Comment

(required) 

(required) 

(optional)

(required) 

Page view counter