ערוך

שתף באמצעות


OdbcCommandBuilder Class

Definition

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

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

Examples

The following example uses OdbcCommand, together with OdbcDataAdapter and OdbcConnection, 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 OdbcCommandBuilder.

public static DataSet SelectOdbcSrvRows(string connectionString,
    string queryString, string tableName)
{
    DataSet dataSet = new DataSet();
    using (OdbcConnection connection = new OdbcConnection(connectionString))
    {
        OdbcDataAdapter adapter = new OdbcDataAdapter();
        adapter.SelectCommand =
            new OdbcCommand(queryString, connection);
        OdbcCommandBuilder builder =
            new OdbcCommandBuilder(adapter);

        connection.Open();

        adapter.Fill(dataSet, tableName);

        //code to modify data in DataSet here

        //Without the OdbcCommandBuilder this line would fail
        adapter.Update(dataSet, tableName);
    }
    return dataSet;
}
Public Function SelectOdbcSrvRows( _
    ByVal connectionString As String, ByVal queryString As String, _
    ByVal tableName As String) As DataSet

    Dim dataSet As New DataSet()

    Using connection As New OdbcConnection(connectionString)
        Dim adapter As New OdbcDataAdapter()
        adapter.SelectCommand = _
            New OdbcCommand(queryString, connection)
        Dim builder As New OdbcCommandBuilder(adapter)

        connection.Open()

        adapter.Fill(dataSet, tableName)

        ' Code to modify data in DataSet here 

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

    Return dataSet
End Function

Remarks

The OdbcDataAdapter does not automatically generate the SQL statements required to reconcile changes made to a DataSet associated with the data source. However, you can create an OdbcCommandBuilder object that generates SQL statements for single-table updates by setting the SelectCommand property of the OdbcDataAdapter. The OdbcCommandBuilder then generates any additional SQL statements that you do not set.

The relationship between an OdbcDataAdapter and its corresponding OdbcCommandBuilder is always one-to-one. To create this correspondence, you set the OdbcDataAdapter property of the OdbcCommandBuilder object. This causes the OdbcCommandBuilder to register itself as a listener, which produces the output of RowUpdating events that affect the DataSet.

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

Note

If the SELECT statement assigned to the SelectCommand property uses aliased column names, the resulting INSERT, UPDATE, and DELETE statements may be inaccurate or fail. If the underlying ODBC driver cannot provide the appropriate base column name for the alias column name (using the SQL_DESC_BASE_COLUMN_NAME value of SQLColAttribute), the alias name could be used in the generated INSERT, UPDATE, and DELETE statements. For example, the Microsoft ODBC Driver for Oracle returns the alias name as the base column name. Therefore, the generated INSERT, UPDATE, and DELETE statements would cause errors.

The OdbcCommandBuilder 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 value of the SelectCommand property itself is changed. Otherwise the InsertCommand, UpdateCommand, and DeleteCommand properties retain their previous values.

If you call Dispose, the OdbcCommandBuilder is disassociated from the OdbcDataAdapter, and the generated commands are no longer used.

Constructors

OdbcCommandBuilder()

Initializes a new instance of the OdbcCommandBuilder class.

OdbcCommandBuilder(OdbcDataAdapter)

Initializes a new instance of the OdbcCommandBuilder class with the associated OdbcDataAdapter object.

Properties

CanRaiseEvents

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

(Inherited from Component)
CatalogLocation

Gets or sets the CatalogLocation for an instance of the DbCommandBuilder class.

(Inherited from DbCommandBuilder)
CatalogSeparator

Gets or sets a string used as the catalog separator for an instance of the DbCommandBuilder class.

(Inherited from DbCommandBuilder)
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 an OdbcDataAdapter object for which this OdbcCommandBuilder object will generate SQL statements.

DesignMode

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

(Inherited from Component)
Events

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

(Inherited from Component)
QuotePrefix

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

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.

(Inherited from DbCommandBuilder)
QuoteSuffix

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

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.

(Inherited from DbCommandBuilder)
SchemaSeparator

Gets or sets the character to be used for the separator between the schema identifier and any other identifiers.

(Inherited from DbCommandBuilder)
SetAllValues

Specifies whether all column values in an update statement are included or only changed ones.

(Inherited from DbCommandBuilder)
Site

Gets or sets the ISite of the Component.

(Inherited from Component)

Methods

ApplyParameterInfo(DbParameter, DataRow, StatementType, Boolean)

Allows the provider implementation of the DbCommandBuilder class to handle additional parameter properties.

(Inherited from DbCommandBuilder)
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(OdbcCommand)

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

Dispose()

Releases all resources used by the Component.

(Inherited from Component)
Dispose(Boolean)

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

(Inherited from DbCommandBuilder)
Dispose(Boolean)

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

(Inherited from Component)
Equals(Object)

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

(Inherited from Object)
GetDeleteCommand()

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

GetDeleteCommand(Boolean)

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

GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetInsertCommand()

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

GetInsertCommand(Boolean)

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

GetLifetimeService()
Obsolete.

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

(Inherited from MarshalByRefObject)
GetParameterName(Int32)

Returns the name of the specified parameter in the format of @p#. Use when building a custom command builder.

(Inherited from DbCommandBuilder)
GetParameterName(String)

Returns the full parameter name, given the partial parameter name.

(Inherited from DbCommandBuilder)
GetParameterPlaceholder(Int32)

Returns the placeholder for the parameter in the associated SQL statement.

(Inherited from DbCommandBuilder)
GetSchemaTable(DbCommand)

Returns the schema table for the DbCommandBuilder.

(Inherited from DbCommandBuilder)
GetService(Type)

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

(Inherited from Component)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
GetUpdateCommand()

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

GetUpdateCommand(Boolean)

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

InitializeCommand(DbCommand)

Resets the CommandTimeout, Transaction, CommandType, and UpdateRowSource properties on the DbCommand.

(Inherited from DbCommandBuilder)
InitializeLifetimeService()
Obsolete.

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

(Inherited from MarshalByRefObject)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean)

Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
QuoteIdentifier(String, OdbcConnection)

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)

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()

Clears the commands associated with this OdbcCommandBuilder.

RefreshSchema()

Clears the commands associated with this DbCommandBuilder.

(Inherited from DbCommandBuilder)
RowUpdatingHandler(RowUpdatingEventArgs)

Adds an event handler for the RowUpdating event.

(Inherited from DbCommandBuilder)
SetRowUpdatingHandler(DbDataAdapter)

Registers the DbCommandBuilder to handle the RowUpdating event for a DbDataAdapter.

(Inherited from DbCommandBuilder)
ToString()

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

(Inherited from Component)
UnquoteIdentifier(String, OdbcConnection)

Given a quoted identifier, returns the correct unquoted form of that identifier, including correctly unescaping any embedded quotes in the identifier.

UnquoteIdentifier(String)

Given a quoted identifier, returns the correct unquoted form of that identifier, including correctly unescaping any embedded quotes in the identifier.

Events

Disposed

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

(Inherited from Component)

Applies to

See also