OleDbCommandBuilder OleDbCommandBuilder OleDbCommandBuilder OleDbCommandBuilder Class

Definition

Automatically generates single-table commands that are used to reconcile changes made to a DataSet with the associated database. This class cannot be inherited.

public ref class OleDbCommandBuilder sealed : System::Data::Common::DbCommandBuilder
public sealed class OleDbCommandBuilder : System.Data.Common.DbCommandBuilder
type OleDbCommandBuilder = class
    inherit DbCommandBuilder
Public NotInheritable Class OleDbCommandBuilder
Inherits DbCommandBuilder
Inheritance

Examples

The following example uses the OleDbCommand, along OleDbDataAdapter and OleDbConnection, to select rows from a data source. The example is passed an initialized DataSet, a connection string, a query string that is an SQL SELECT statement, and a string that is the name of the data source table. The example then creates an OleDbCommandBuilder.

public static DataSet UpdateRows(string connectionString,
    string queryString, string tableName)
{
    DataSet dataSet = new DataSet();
    using (OleDbConnection connection = new OleDbConnection(connectionString))
    {
        OleDbDataAdapter adapter = new OleDbDataAdapter();
        adapter.SelectCommand = new OleDbCommand(queryString, connection);
        OleDbCommandBuilder cb = new OleDbCommandBuilder(adapter);

        connection.Open();

        adapter.Fill(dataSet, tableName);

        //code to modify data in DataSet here

        cb.GetDeleteCommand();
        //Without the OleDbCommandBuilder this line would fail
        adapter.Update(dataSet, tableName);

        connection.Close();
    }
    return dataSet;
}
Public Shared Function UpdateRows(ByVal connectionString As String, _
ByVal queryString As String, ByVal tableName As String) As DataSet

    Dim dataSet As New DataSet()

    Using connection As New OleDbConnection(connectionString)
        Dim adapter As New OleDbDataAdapter()
        adapter.SelectCommand = New OleDbCommand(queryString, connection)
        Dim builder As New OleDbCommandBuilder(adapter)

        connection.Open()

        adapter.Fill(dataSet, tableName)

        ' Code to modify data in DataSet here 

        builder.GetUpdateCommand()

        ' Without the OleDbCommandBuilder this line would fail.
        adapter.Update(dataSet, tableName)
    End Using

    Return dataSet
End Function

Remarks

The OleDbDataAdapter does not automatically generate the SQL statements required to reconcile changes made to a DataSet with the associated data source. However, you can create an OleDbCommandBuilder object to automatically generate SQL statements for single-table updates if you set the SelectCommand property of the OleDbDataAdapter. Then, any additional SQL statements that you do not set are generated by the OleDbCommandBuilder.

The OleDbCommandBuilder registers itself as a listener for RowUpdating events whenever you set the DataAdapter property. You can only associate one OleDbDataAdapter or OleDbCommandBuilder object with each other at one time.

To generate INSERT, UPDATE, or DELETE statements, the OleDbCommandBuilder uses the SelectCommand property to retrieve a required set of metadata automatically. If you change the SelectCommand after the metadata is retrieved, such as after the first update, you should call the RefreshSchema method to update the metadata.

The OleDbCommandBuilder 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 OleDbCommandBuilder is disassociated from the OleDbDataAdapter, and the generated commands are no longer used.

Constructors

OleDbCommandBuilder() OleDbCommandBuilder() OleDbCommandBuilder() OleDbCommandBuilder()

Initializes a new instance of the OleDbCommandBuilder class.

OleDbCommandBuilder(OleDbDataAdapter) OleDbCommandBuilder(OleDbDataAdapter) OleDbCommandBuilder(OleDbDataAdapter) OleDbCommandBuilder(OleDbDataAdapter)

Initializes a new instance of the OleDbCommandBuilder class with the associated OleDbDataAdapter object.

Properties

CanRaiseEvents CanRaiseEvents CanRaiseEvents CanRaiseEvents

Gets a value indicating whether the component can raise an event.

(Inherited from Component)
Container Container Container Container

Gets the IContainer that contains the Component.

(Inherited from Component)
DataAdapter DataAdapter DataAdapter DataAdapter

Gets or sets an OleDbDataAdapter object for which SQL statements are automatically generated.

DesignMode DesignMode DesignMode DesignMode

Gets a value that indicates whether the Component is currently in design mode.

(Inherited from Component)
Events Events Events Events

Gets the list of event handlers that are attached to this Component.

(Inherited from Component)
QuotePrefix QuotePrefix QuotePrefix QuotePrefix

Gets or sets the beginning character or characters to use when specifying database objects (for example, tables or columns) whose names contain characters such as spaces or reserved tokens.

QuoteSuffix QuoteSuffix QuoteSuffix QuoteSuffix

Gets or sets the ending character or characters to use when specifying database objects (for example, tables or columns) whose names contain characters such as spaces or reserved tokens.

Site Site Site Site

Gets or sets the ISite of the Component.

(Inherited from Component)

Methods

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) 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(OleDbCommand) DeriveParameters(OleDbCommand) DeriveParameters(OleDbCommand) DeriveParameters(OleDbCommand)

Retrieves parameter information from the stored procedure specified in the OleDbCommand and populates the Parameters collection of the specified OleDbCommand object.

Dispose() Dispose() Dispose() Dispose()

Releases all resources used by the Component.

(Inherited from Component)
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

Releases the unmanaged resources used by the Component and optionally releases the managed resources.

(Inherited from Component)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetDeleteCommand() GetDeleteCommand() GetDeleteCommand() GetDeleteCommand()

Gets the automatically generated OleDbCommand object required to perform deletions at the data source.

GetDeleteCommand(Boolean) GetDeleteCommand(Boolean) GetDeleteCommand(Boolean) GetDeleteCommand(Boolean)

Gets the automatically generated OleDbCommand object required to perform deletions at the data source.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetInsertCommand() GetInsertCommand() GetInsertCommand() GetInsertCommand()

Gets the automatically generated OleDbCommand object required to perform insertions at the data source.

GetInsertCommand(Boolean) GetInsertCommand(Boolean) GetInsertCommand(Boolean) GetInsertCommand(Boolean)

Gets the automatically generated OleDbCommand object required to perform insertions at the data source.

GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetService(Type) GetService(Type) GetService(Type) GetService(Type)

Returns an object that represents a service provided by the Component or by its Container.

(Inherited from Component)
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
GetUpdateCommand() GetUpdateCommand() GetUpdateCommand() GetUpdateCommand()

Gets the automatically generated OleDbCommand object required to perform updates at the data source.

GetUpdateCommand(Boolean) GetUpdateCommand(Boolean) GetUpdateCommand(Boolean) GetUpdateCommand(Boolean)

Gets the automatically generated OleDbCommand object required to perform updates at the data source, optionally using columns for parameter names.

InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
QuoteIdentifier(String) QuoteIdentifier(String) QuoteIdentifier(String) 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.

QuoteIdentifier(String, OleDbConnection) QuoteIdentifier(String, OleDbConnection) QuoteIdentifier(String, OleDbConnection) QuoteIdentifier(String, OleDbConnection)

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.

RefreshSchema() RefreshSchema() RefreshSchema() RefreshSchema()

Clears the commands associated with this OleDbCommandBuilder.

ToString() ToString() ToString() ToString()

Returns a String containing the name of the Component, if any. This method should not be overridden.

(Inherited from Component)
UnquoteIdentifier(String) UnquoteIdentifier(String) UnquoteIdentifier(String) UnquoteIdentifier(String)

Given a quoted identifier, returns the correct unquoted form of that identifier. This includes correctly un-escaping any embedded quotes in the identifier.

UnquoteIdentifier(String, OleDbConnection) UnquoteIdentifier(String, OleDbConnection) UnquoteIdentifier(String, OleDbConnection) UnquoteIdentifier(String, OleDbConnection)

Given a quoted identifier, returns the correct unquoted form of that identifier. This includes correctly un-escaping any embedded quotes in the identifier.

Events

Disposed Disposed Disposed Disposed

Occurs when the component is disposed by a call to the Dispose() method.

(Inherited from Component)

Applies to

See also