SqlCommandBuilder Class
Automatically generates single-table commands that are used to reconcile changes made to a DataSet with the associated SQL Server database. This class cannot be inherited.
Assembly: System.Data (in System.Data.dll)
System::MarshalByRefObject
System.ComponentModel::Component
System.Data.Common::DbCommandBuilder
System.Data.SqlClient::SqlCommandBuilder
| Name | Description | |
|---|---|---|
![]() | SqlCommandBuilder() | Initializes a new instance of the SqlCommandBuilder class. |
![]() | SqlCommandBuilder(SqlDataAdapter^) | Initializes a new instance of the SqlCommandBuilder class with the associated SqlDataAdapter object. |
| Name | Description | |
|---|---|---|
![]() | CatalogLocation | Sets or gets the CatalogLocation for an instance of the SqlCommandBuilder class.(Overrides DbCommandBuilder::CatalogLocation.) |
![]() | CatalogSeparator | Sets or gets a string used as the catalog separator for an instance of the SqlCommandBuilder class.(Overrides DbCommandBuilder::CatalogSeparator.) |
![]() | ConflictOption | Specifies which ConflictOption is to be used by the DbCommandBuilder.(Inherited from DbCommandBuilder.) |
![]() | Container | Gets the IContainer that contains the Component.(Inherited from Component.) |
![]() | DataAdapter | Gets or sets a SqlDataAdapter object for which Transact-SQL statements are automatically generated. |
![]() | QuotePrefix | Gets or sets the starting character or characters to use when specifying SQL Server database objects, such as tables or columns, whose names contain characters such as spaces or reserved tokens.(Overrides DbCommandBuilder::QuotePrefix.) |
![]() | QuoteSuffix | Gets or sets the ending character or characters to use when specifying SQL Server database objects, such as tables or columns, whose names contain characters such as spaces or reserved tokens.(Overrides DbCommandBuilder::QuoteSuffix.) |
![]() | SchemaSeparator | Gets or sets the character to be used for the separator between the schema identifier and any other identifiers.(Overrides DbCommandBuilder::SchemaSeparator.) |
![]() | SetAllValues | Specifies whether all column values in an update statement are included or only changed ones.(Inherited from DbCommandBuilder.) |
![]() | Site |
| Name | Description | |
|---|---|---|
![]() | CreateObjRef(Type^) | Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.(Inherited from MarshalByRefObject.) |
![]() ![]() | DeriveParameters(SqlCommand^) | Retrieves parameter information from the stored procedure specified in the SqlCommand and populates the Parameters collection of the specified SqlCommand object. |
![]() | Dispose() | |
![]() | Equals(Object^) | Determines whether the specified object is equal to the current object.(Inherited from Object.) |
![]() | GetDeleteCommand() | Gets the automatically generated SqlCommand object required to perform deletions on the database. |
![]() | GetDeleteCommand(Boolean) | Gets the automatically generated SqlCommand object that is required to perform deletions on the database. |
![]() | GetHashCode() | Serves as the default hash function. (Inherited from Object.) |
![]() | GetInsertCommand() | Gets the automatically generated SqlCommand object required to perform insertions on the database. |
![]() | GetInsertCommand(Boolean) | Gets the automatically generated SqlCommand object that is required to perform insertions on the database. |
![]() | GetLifetimeService() | Retrieves the current lifetime service object that controls the lifetime policy for this instance.(Inherited from MarshalByRefObject.) |
![]() | GetType() | |
![]() | GetUpdateCommand() | Gets the automatically generated SqlCommand object required to perform updates on the database. |
![]() | GetUpdateCommand(Boolean) | Gets the automatically generated SqlCommand object required to perform updates on the database. |
![]() | InitializeLifetimeService() | Obtains a lifetime service object to control the lifetime policy for this instance.(Inherited from MarshalByRefObject.) |
![]() | QuoteIdentifier(String^) | Given an unquoted identifier in the correct catalog case, returns the correct quoted form of that identifier. This includes correctly escaping any embedded quotes in the identifier.(Overrides DbCommandBuilder::QuoteIdentifier(String^).) |
![]() | RefreshSchema() | Clears the commands associated with this DbCommandBuilder.(Inherited from DbCommandBuilder.) |
![]() | ToString() | |
![]() | UnquoteIdentifier(String^) | Given a quoted identifier, returns the correct unquoted form of that identifier. This includes correctly unescaping any embedded quotes in the identifier.(Overrides DbCommandBuilder::UnquoteIdentifier(String^).) |
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 a 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 been retrieved, such as 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 SqlCommandBuilder also uses the Connection, CommandTimeout, and Transaction properties referenced by the SelectCommand. The user should call RefreshSchema if one or more 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 example uses the SqlCommand, along SqlDataAdapter and SqlConnection, to select rows from a data source. The example is passed a connection string, a query string that is a Transact-SQL SELECT statement, and a string that is the name of the database table. The example then creates a SqlCommandBuilder.
Available since 1.1
Any public static ( Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.



