OdbcCommandBuilder 类

定义

自动生成用于协调对 DataSet 的更改与关联的数据源的单表命令。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
继承
继承
OdbcCommandBuilder

示例

下面的示例使用 OdbcCommand,以及 OdbcDataAdapterOdbcConnection从数据源中选择行。The following example uses OdbcCommand, together with OdbcDataAdapter and OdbcConnection, to select rows from a data source. 该示例传递了一个初始化的 DataSet、一个连接字符串、一个 SQL SELECT 语句的查询字符串以及一个作为数据源表名称的字符串。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. 然后,该示例创建一个 OdbcCommandBuilderThe 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

注解

OdbcDataAdapter 不会自动生成对与数据源关联的 DataSet 所做的更改进行协调所需的 SQL 语句。The OdbcDataAdapter does not automatically generate the SQL statements required to reconcile changes made to a DataSet associated with the data source. 但是,您可以通过设置 OdbcDataAdapterSelectCommand 属性,创建一个为单表更新生成 SQL 语句的 OdbcCommandBuilder 对象。However, you can create an OdbcCommandBuilder object that generates SQL statements for single-table updates by setting the SelectCommand property of the OdbcDataAdapter. 然后,OdbcCommandBuilder 会生成未设置的任何其他 SQL 语句。The OdbcCommandBuilder then generates any additional SQL statements that you do not set.

OdbcDataAdapter 与其对应的 OdbcCommandBuilder 之间的关系始终为一对一关系。The relationship between an OdbcDataAdapter and its corresponding OdbcCommandBuilder is always one-to-one. 若要创建此函件,请设置 OdbcCommandBuilder 对象的 OdbcDataAdapter 属性。To create this correspondence, you set the OdbcDataAdapter property of the OdbcCommandBuilder object. 这会导致 OdbcCommandBuilder 将自身注册为侦听器,这会生成影响 DataSetRowUpdating 事件的输出。This causes the OdbcCommandBuilder to register itself as a listener, which produces the output of RowUpdating events that affect the DataSet.

若要生成 INSERT、UPDATE 或 DELETE 语句,OdbcCommandBuilder 使用 SelectCommand 属性来检索所需的一组元数据。To generate INSERT, UPDATE, or DELETE statements, the OdbcCommandBuilder uses the SelectCommand property to retrieve a required set of metadata. 如果在检索元数据后更改 SelectCommand 的值(例如第一次更新后),则应调用 RefreshSchema 方法来更新元数据。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.

备注

如果分配给 SelectCommand 属性的 SELECT 语句使用别名列名称,则生成的 INSERT、UPDATE 和 DELETE 语句可能不准确或失败。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. 如果基础 ODBC 驱动程序无法为别名列名(使用 SQLColAttribute的 SQL_DESC_BASE_COLUMN_NAME 值)提供相应的基本列名称,则可以在生成的 INSERT、UPDATE 和 DELETE 语句中使用别名。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. 例如,用于 Oracle 的 Microsoft ODBC 驱动程序返回别名作为基列名称。For example, the Microsoft ODBC Driver for Oracle returns the alias name as the base column name. 因此,生成的 INSERT、UPDATE 和 DELETE 语句将导致错误。Therefore, the generated INSERT, UPDATE, and DELETE statements would cause errors.

OdbcCommandBuilder 还使用 SelectCommand引用的 ConnectionCommandTimeoutTransaction 属性。The OdbcCommandBuilder also uses the Connection, CommandTimeout, and Transaction properties referenced by the SelectCommand. 如果修改了这些属性中的一个或多个,或者 SelectCommand 属性本身的值发生更改,则用户应调用 RefreshSchemaThe user should call RefreshSchema if one or more of these properties are modified, or if the value of the SelectCommand property itself is changed. 否则,InsertCommandUpdateCommandDeleteCommand 属性保留其以前的值。Otherwise the InsertCommand, UpdateCommand, and DeleteCommand properties retain their previous values.

如果调用 Dispose,则 OdbcCommandBuilder 会与 OdbcDataAdapter解除关联,不再使用生成的命令。If you call Dispose, the OdbcCommandBuilder is disassociated from the OdbcDataAdapter, and the generated commands are no longer used.

构造函数

OdbcCommandBuilder()

初始化 OdbcCommandBuilder 类的新实例。Initializes a new instance of the OdbcCommandBuilder class.

OdbcCommandBuilder(OdbcDataAdapter)

使用关联的 OdbcCommandBuilder 对象初始化 OdbcDataAdapter 类的新实例。Initializes a new instance of the OdbcCommandBuilder class with the associated OdbcDataAdapter object.

属性

CanRaiseEvents

获取一个指示组件是否可以引发事件的值。Gets a value indicating whether the component can raise an event.

(继承自 Component)
CatalogLocation

获取或设置 DbCommandBuilder 类的实例的 CatalogLocationGets or sets the CatalogLocation for an instance of the DbCommandBuilder class.

(继承自 DbCommandBuilder)
CatalogSeparator

获取或设置一个字符串,该字符串用作 DbCommandBuilder 类的实例的目录分隔符。Gets or sets a string used as the catalog separator for an instance of the DbCommandBuilder class.

(继承自 DbCommandBuilder)
ConflictOption

指定哪个 ConflictOption 将由 DbCommandBuilder 使用。Specifies which ConflictOption is to be used by the DbCommandBuilder.

(继承自 DbCommandBuilder)
Container

获取包含 IContainerComponentGets the IContainer that contains the Component.

(继承自 Component)
DataAdapter

获取或设置此 OdbcDataAdapter 对象将为其生成 SQL 语句的 OdbcCommandBuilder 对象。Gets or sets an OdbcDataAdapter object for which this OdbcCommandBuilder object will generate SQL statements.

DesignMode

获取一个值,用以指示 Component 当前是否处于设计模式。Gets a value that indicates whether the Component is currently in design mode.

(继承自 Component)
Events

获取附加到此 Component 的事件处理程序的列表。Gets the list of event handlers that are attached to this Component.

(继承自 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.

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.

SchemaSeparator

获取或设置要用作架构标识符和任何其他标识符之间的分隔符的字符。Gets or sets the character to be used for the separator between the schema identifier and any other identifiers.

(继承自 DbCommandBuilder)
SetAllValues

指定 update 语句中是包含所有列值还是仅包含更改的列值。Specifies whether all column values in an update statement are included or only changed ones.

(继承自 DbCommandBuilder)
Site

获取或设置 ISiteComponentGets or sets the ISite of the Component.

(继承自 Component)

方法

ApplyParameterInfo(DbParameter, DataRow, StatementType, Boolean)

允许 DbCommandBuilder 类的提供程序实现处理附加参数属性。Allows the provider implementation of the DbCommandBuilder class to handle additional parameter properties.

(继承自 DbCommandBuilder)
CreateObjRef(Type)

创建一个对象,该对象包含生成用于与远程对象进行通信的代理所需的全部相关信息。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(继承自 MarshalByRefObject)
DeriveParameters(OdbcCommand)

从在 OdbcCommand 中指定的存储过程中检索参数信息并填充指定的 Parameters 对象的 OdbcCommand 集合。Retrieves parameter information from the stored procedure specified in the OdbcCommand and populates the Parameters collection of the specified OdbcCommand object.

Dispose()

释放由 Component 使用的所有资源。Releases all resources used by the Component.

(继承自 Component)
Dispose(Boolean)

释放由 Component 占用的非托管资源,还可以另外再释放托管资源。Releases the unmanaged resources used by the Component and optionally releases the managed resources.

(继承自 Component)
Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetDeleteCommand()

获取在数据源中执行删除操作所需的自动生成的 OdbcCommand 对象。Gets the automatically generated OdbcCommand object required to perform deletions at the data source.

GetDeleteCommand(Boolean)

获取在数据源中执行删除操作所需的自动生成的 OdbcCommand 对象。Gets the automatically generated OdbcCommand object required to perform deletions at the data source.

GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetInsertCommand()

获取在数据源中执行插入操作所需的自动生成的 OdbcCommand 对象。Gets the automatically generated OdbcCommand object required to perform insertions at the data source.

GetInsertCommand(Boolean)

获取在数据源中执行插入操作所需的自动生成的 OdbcCommand 对象。Gets the automatically generated OdbcCommand object required to perform insertions at the data source.

GetLifetimeService()

检索控制此实例的生存期策略的当前生存期服务对象。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(继承自 MarshalByRefObject)
GetParameterName(Int32)

@p# 格式返回指定参数的名称。Returns the name of the specified parameter in the format of @p#. 在生成自定义命令生成器时使用。Use when building a custom command builder.

(继承自 DbCommandBuilder)
GetParameterName(String)

给定部分参数名,返回完整参数名。Returns the full parameter name, given the partial parameter name.

(继承自 DbCommandBuilder)
GetParameterPlaceholder(Int32)

返回该参数在关联的 SQL 语句中的占位符。Returns the placeholder for the parameter in the associated SQL statement.

(继承自 DbCommandBuilder)
GetSchemaTable(DbCommand)

返回 DbCommandBuilder 的架构表。Returns the schema table for the DbCommandBuilder.

(继承自 DbCommandBuilder)
GetService(Type)

返回一个对象,该对象表示由 Component 或它的 Container 提供的服务。Returns an object that represents a service provided by the Component or by its Container.

(继承自 Component)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
GetUpdateCommand()

获取在数据源中执行更新操作所需的自动生成的 OdbcCommand 对象。Gets the automatically generated OdbcCommand object required to perform updates at the data source.

GetUpdateCommand(Boolean)

获取在数据源中执行更新操作所需的自动生成的 OdbcCommand 对象。Gets the automatically generated OdbcCommand object required to perform updates at the data source.

InitializeCommand(DbCommand)

重置 CommandTimeout 上的 TransactionCommandTypeUpdateRowSourceDbCommand 属性。Resets the CommandTimeout, Transaction, CommandType, and UpdateRowSource properties on the DbCommand.

(继承自 DbCommandBuilder)
InitializeLifetimeService()

获取生存期服务对象来控制此实例的生存期策略。Obtains a lifetime service object to control the lifetime policy for this instance.

(继承自 MarshalByRefObject)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
MemberwiseClone(Boolean)

创建当前 MarshalByRefObject 对象的浅表副本。Creates a shallow copy of the current MarshalByRefObject object.

(继承自 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.

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.

RefreshSchema()

清除与此 OdbcCommandBuilder 关联的命令。Clears the commands associated with this OdbcCommandBuilder.

RowUpdatingHandler(RowUpdatingEventArgs)

添加 RowUpdating 事件的事件处理程序。Adds an event handler for the RowUpdating event.

(继承自 DbCommandBuilder)
SetRowUpdatingHandler(DbDataAdapter)

注册 DbCommandBuilder 以处理 RowUpdatingDbDataAdapter 事件。Registers the DbCommandBuilder to handle the RowUpdating event for a DbDataAdapter.

(继承自 DbCommandBuilder)
ToString()

返回包含 String 的名称的 Component(如果有)。Returns a String containing the name of the Component, if any. 不应重写此方法。This method should not be overridden.

(继承自 Component)
UnquoteIdentifier(String)

给定了带引号的标识符时,返回该标识符的正确的不带引号形式,包括正确地非转义该标识符中的任何嵌入引号。Given a quoted identifier, returns the correct unquoted form of that identifier, including correctly unescaping any embedded quotes in the identifier.

UnquoteIdentifier(String, OdbcConnection)

给定了带引号的标识符时,返回该标识符的正确的不带引号形式,包括正确地非转义该标识符中的任何嵌入引号。Given a quoted identifier, returns the correct unquoted form of that identifier, including correctly unescaping any embedded quotes in the identifier.

事件

Disposed

在通过调用 Dispose() 方法释放组件时发生。Occurs when the component is disposed by a call to the Dispose() method.

(继承自 Component)

适用于

另请参阅