System.Data.SqlClient Namespace
Provides a means of automatically generating single-table commands used to reconcile changes made to a DataSet with the associated SQL Server™ database.
The SqlDataAdapter does not automatically generate the Transact-SQL statements required to reconcile changes made to a DataSet with the associated instance of SQL Server. However, you can create an SqlCommandBuilder object to automatically generate Transact-SQL statements for single-table updates if you set the SelectCommand property of the SqlDataAdapter. Then, any additional Transact-SQL statements that you do not set are generated by the SqlCommandBuilder.
The SqlCommandBuilder registers itself as a listener for RowUpdating events whenever you set the DataAdapter property. You can only associate one SqlDataAdapter or SqlCommandBuilder object with each other at one time.
To generate INSERT, UPDATE, or DELETE statements, the SqlCommandBuilder uses the SelectCommand property to retrieve a required set of metadata automatically. If you change the SelectCommand after the metadata has is retrieved ( for example, after the first update ), you should call the RefreshSchema method to update the metadata.
The SqlCommandBuilder also uses the Connection, CommandTimeout, and Transaction properties referenced by the SelectCommand. The user 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 SqlCommandBuilder is disassociated from the SqlDataAdapter, and the generated commands are no longer used.
The following examples demonstrate using the SqlCommandBuilder to dynamically generate the INSERT, UPDATE, and DELETE statements of a given SqlDataAdapter.
SqlCommand SqlDataAdapter Updating Data at the DataSet Level