Assembly: System.Data (in system.data.dll)
The DbCommandBuilder class is provided for the convenience of provider writers creating their own command builders. By inheriting from this class, developers can implement provider specific behavior in their own code.
The DbDataAdapter does not automatically generate the SQL statements required to reconcile changes made to a DataSet with the associated data source. However, you can create a DbCommandBuilder object to automatically generate SQL statements for single-table updates if you set the SelectCommand property of the DbDataAdapter. Then, any additional SQL statements that you do not set are generated by the DbCommandBuilder.
The DbCommandBuilder registers itself as a listener for RowUpdating events whenever you set the DataAdapter property. You can only associate one DbDataAdapter or DbCommandBuilder object with each other at one time.
To generate INSERT, UPDATE, or DELETE statements, the DbCommandBuilder uses the SelectCommand property to retrieve a required set of metadata automatically. If you change the SelectCommand after the metadata has been 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 exist, an InvalidOperationException exception is generated, and the commands are not generated.
The DbCommandBuilder 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 DbCommandBuilder is disassociated from the DbDataAdapter, and the generated commands are no longer used.
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.