Assembly: System.Data.SqlServerCe (in system.data.sqlserverce.dll)
You can create a SqlCeCommandBuilder object to automatically generate Transact-SQL statements for single-table updates if you set the SelectCommand property.
The SqlCeCommandBuilder registers itself as a listener for RowUpdating events whenever you set the DataAdapter property. You can only associate one SqlCeDataAdapter or SqlCeCommandBuilder object with each other at one time.
To generate INSERT, UPDATE, or DELETE statements, the SqlCeCommandBuilder uses the SelectCommand property to retrieve a required set of metadata automatically. If you change the SelectCommand after the metadata is retrieved (for example, after the first update), you should call the RefreshSchema method to update the metadata.
The SelectCommand must also return at least one primary key or unique column. If none are present, an InvalidOperation exception is generated, and the commands are not generated.
The SqlCeCommandBuilder also uses the Connection and Transaction properties referenced by the SelectCommand. You should call RefreshSchema if any of these properties are modified, or if the SelectCommand itself is replaced. Otherwise, the InsertCommand, UpdateCommand, and DeleteCommand properties retain their previous values.
If you call Dispose, the SqlCeCommandBuilder is disassociated from the SqlCeDataAdapter, and the generated commands are no longer used.
The following example uses the SqlCeCommand, along with SqlCeDataAdapter and SqlCeConnection, to select rows from a data source. The example is passed a connection string, a query string, and a string that is the name of the database table. The example then creates a SqlCeCommandBuilder. That command builder is then used by the data adapter to update the modified DataSet in the local database.