Export (0) Print
Expand All

DbCommandBuilder Class

Automatically generates single-table commands used to reconcile changes made to a DataSet with the associated database. This is an abstract class that can only be inherited.

Namespace:  System.Data.Common
Assembly:  System.Data (in System.Data.dll)

public abstract class DbCommandBuilder : Component

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.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0

.NET Compact Framework

Supported in: 3.5, 2.0

XNA Framework

Supported in: 3.0, 2.0, 1.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

Show:
© 2014 Microsoft