DbCommand Class

Definition

表示要对数据源执行的 SQL 语句或存储过程。Represents an SQL statement or stored procedure to execute against a data source. 提供表示命令的数据库特定类的基类。Provides a base class for database-specific classes that represent commands. ExecuteNonQueryAsync

public ref class DbCommand abstract : IDisposable
public ref class DbCommand abstract : System::ComponentModel::Component, IAsyncDisposable, IDisposable, System::Data::IDbCommand
public ref class DbCommand abstract : IDisposable, System::Data::IDbCommand
public ref class DbCommand abstract : System::ComponentModel::Component, IDisposable, System::Data::IDbCommand
public ref class DbCommand abstract : System::ComponentModel::Component, System::Data::IDbCommand
public ref class DbCommand abstract : System::ComponentModel::Component, IAsyncDisposable, System::Data::IDbCommand
public abstract class DbCommand : IDisposable
public abstract class DbCommand : System.ComponentModel.Component, IAsyncDisposable, IDisposable, System.Data.IDbCommand
public abstract class DbCommand : IDisposable, System.Data.IDbCommand
public abstract class DbCommand : System.ComponentModel.Component, IDisposable, System.Data.IDbCommand
public abstract class DbCommand : System.ComponentModel.Component, System.Data.IDbCommand
public abstract class DbCommand : System.ComponentModel.Component, IAsyncDisposable, System.Data.IDbCommand
type DbCommand = class
    interface IDisposable
type DbCommand = class
    inherit Component
    interface IDbCommand
    interface IDisposable
    interface IAsyncDisposable
type DbCommand = class
    interface IDbCommand
    interface IDisposable
type DbCommand = class
    inherit Component
    interface IDbCommand
    interface IDisposable
Public MustInherit Class DbCommand
Implements IDisposable
Public MustInherit Class DbCommand
Inherits Component
Implements IAsyncDisposable, IDbCommand, IDisposable
Public MustInherit Class DbCommand
Implements IDbCommand, IDisposable
Public MustInherit Class DbCommand
Inherits Component
Implements IDbCommand, IDisposable
Public MustInherit Class DbCommand
Inherits Component
Implements IDbCommand
Public MustInherit Class DbCommand
Inherits Component
Implements IAsyncDisposable, IDbCommand
Inheritance
DbCommand
Inheritance
Derived
Implements

Constructors

DbCommand()

构造 DbCommand 对象的实例。Constructs an instance of the DbCommand object.

Properties

CanRaiseEvents

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

(Inherited from Component)
CommandText

在派生类中重写时,获取或设置对数据源运行的文本命令。When overridden in a derived class, gets or sets the text command to run against the data source.

CommandTimeout

在派生类中重写时,获取或设置在终止尝试执行命令并生成错误之前的等待时间(以秒为单位)。When overridden in a derived class, gets or sets the wait time (in seconds) before terminating the attempt to execute a command and generating an error.

CommandType

在派生类中重写时,获取或设置 CommandText 属性的解释方式。When overridden in a derived class, gets or sets how the CommandText property is interpreted.

Connection

获取或设置此 DbConnection 使用的 DbCommandGets or sets the DbConnection used by this DbCommand.

Container

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

(Inherited from Component)
DbConnection

当在派生类中重写时,获取或设置此 DbCommand 使用的 DbConnectionWhen overridden in a derived class, gets or sets the DbConnection used by this DbCommand.

DbParameterCollection

在派生类中重写时,获取 DbParameter 对象的集合。When overridden in a derived class, gets the collection of DbParameter objects.

DbTransaction

当在派生类中重写时,获取或设置执行 DbCommand 对象时所在的 DbTransactionWhen overridden in a derived class, gets or sets the DbTransaction within which this DbCommand object executes.

DesignMode

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

(Inherited from Component)
DesignTimeVisible

当在派生类中重写时,获取或设置一个值,该值指示此命令对象在自定义界面控件中是否可见。When overridden in a derived class, gets or sets a value indicating whether the command object should be visible in a customized interface control.

Events

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

(Inherited from Component)
Parameters

获取 DbParameter 对象的集合。Gets the collection of DbParameter objects. 有关参数的详细信息,请参阅配置参数和参数数据类型For more information on parameters, see Configuring Parameters and Parameter Data Types.

Site

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

(Inherited from Component)
Transaction

获取或设置将在其中执行此 DbCommand 对象的 DbTransactionGets or sets the DbTransaction within which this DbCommand object executes.

UpdatedRowSource

当在派生类中重写时,获取或设置命令结果在由 DataRow 的 Update 方法使用时如何应用于 DbDataAdapterWhen overridden in a derived class, gets or sets how command results are applied to the DataRow when used by the Update method of a DbDataAdapter.

Methods

Cancel()

在派生类中重写时,尝试取消 DbCommand 的执行。When overridden in a derived class, attempts to cancel the execution of a DbCommand.

CreateDbParameter()

在派生类中重写时,创建 DbParameter 对象的新实例。When overridden in a derived class, creates a new instance of a DbParameter object.

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

创建 DbParameter 对象的新实例。Creates a new instance of a DbParameter object.

Dispose()
Dispose()

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

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

释放 Component 使用的非托管资源,并选择性地释放托管资源。Releases the unmanaged resources used by the Component and optionally releases the managed resources.

(Inherited from Component)
DisposeAsync()

异步处置命令对象。Asynchronously diposes the command object.

Equals(Object)

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

(Inherited from Object)
ExecuteDbDataReader(CommandBehavior)

当在派生类中重写时,针对连接执行命令文本。When overridden in a derived class, executes the command text against the connection.

ExecuteDbDataReaderAsync(CommandBehavior, CancellationToken)

提供程序应执行该方法对 ExecuteReader 重载提供非默认的实现。Providers should implement this method to provide a non-default implementation for ExecuteReader overloads.

默认实现调用同步 ExecuteReader() 方法并返回已完成任务,以便阻止调用线程。The default implementation invokes the synchronous ExecuteReader() method and returns a completed task, blocking the calling thread. 如果传递到已取消的取消标记,则默认实现将返回已取消的任务。The default implementation will return a cancelled task if passed an already cancelled cancellation token. ExecuteReader 引发的异常将通过返回的任务异常属性传递。Exceptions thrown by ExecuteReader will be communicated via the returned Task Exception property.

该方法可用于请求操作之前接受取消标记。This method accepts a cancellation token that can be used to request the operation to be cancelled early. 实现可能会忽略该请求。Implementations may ignore this request.

ExecuteNonQuery()

当在派生类中重写时,针对连接对象执行 SQL 语句。When overridden in a derived class, executes a SQL statement against a connection object.

ExecuteNonQueryAsync()

ExecuteNonQuery()的异步版本,针对一个连接对象执行一个 SQL 声明。An asynchronous version of ExecuteNonQuery(), which executes a SQL statement against a connection object.

通过 CancellationToken.None 调用 ExecuteNonQueryAsync(CancellationToken)Invokes ExecuteNonQueryAsync(CancellationToken) with CancellationToken.None.

ExecuteNonQueryAsync(CancellationToken)

这是 ExecuteNonQuery() 的异步版本。This is the asynchronous version of ExecuteNonQuery(). 提供程序应使用合适的实现进行重写。Providers should override with an appropriate implementation. 可选择性忽略取消标记。The cancellation token may optionally be ignored.

默认实现调用同步 ExecuteNonQuery() 方法并返回已完成任务,以便阻止调用线程。The default implementation invokes the synchronous ExecuteNonQuery() method and returns a completed task, blocking the calling thread. 如果传递到已取消的取消标记,则默认实现将返回已取消的任务。The default implementation will return a cancelled task if passed an already cancelled cancellation token. ExecuteNonQuery() 引发的异常将通过任务异常属性传递。Exceptions thrown by ExecuteNonQuery() will be communicated via the returned Task Exception property.

在返回的任务完成前,不要调用 DbCommand 对象的其他方法和属性。Do not invoke other methods and properties of the DbCommand object until the returned Task is complete.

ExecuteReader()

针对 CommandText 执行 Connection,并返回 DbDataReaderExecutes the CommandText against the Connection, and returns an DbDataReader.

ExecuteReader(CommandBehavior)

针对 CommandText 执行 Connection,并使用 DbDataReader 值之一返回 CommandBehaviorExecutes the CommandText against the Connection, and returns an DbDataReader using one of the CommandBehavior values.

ExecuteReaderAsync()

ExecuteReader 的异步版本,针对 CommandTextConnection 执行 DbDataReaderAn asynchronous version of ExecuteReader, which executes the CommandText against the Connection and returns a DbDataReader.

通过 CancellationToken.None 调用 ExecuteDbDataReaderAsync(CommandBehavior, CancellationToken)Invokes ExecuteDbDataReaderAsync(CommandBehavior, CancellationToken) with CancellationToken.None.

ExecuteReaderAsync(CancellationToken)

ExecuteReader 的异步版本,针对 CommandTextConnection 执行 DbDataReaderAn asynchronous version of ExecuteReader, which executes the CommandText against the Connection and returns a DbDataReader. 此方法传播有关应取消操作的通知。This method propagates a notification that operations should be canceled.

调用 ExecuteDbDataReaderAsync(CommandBehavior, CancellationToken).Invokes ExecuteDbDataReaderAsync(CommandBehavior, CancellationToken).

ExecuteReaderAsync(CommandBehavior)

ExecuteReader 的异步版本,针对 CommandTextConnection 执行 DbDataReaderAn asynchronous version of ExecuteReader, which executes the CommandText against the Connection and returns a DbDataReader.

调用 ExecuteDbDataReaderAsync(CommandBehavior, CancellationToken).Invokes ExecuteDbDataReaderAsync(CommandBehavior, CancellationToken).

ExecuteReaderAsync(CommandBehavior, CancellationToken)

调用 ExecuteDbDataReaderAsync(CommandBehavior, CancellationToken).Invokes ExecuteDbDataReaderAsync(CommandBehavior, CancellationToken).

ExecuteScalar()

当在派生类中重写时,执行查询,并将查询返回的结果集中第一行的第一列返回。When overridden in a derived class, executes the query and returns the first column of the first row in the result set returned by the query. 所有其他的列和行将被忽略。All other columns and rows are ignored.

ExecuteScalarAsync()

ExecuteScalar() 的异步版本,执行查询,并将查询返回的结果集中第一行的第一列返回。An asynchronous version of ExecuteScalar(), which executes the query and returns the first column of the first row in the result set returned by the query. 所有其他的列和行将被忽略。All other columns and rows are ignored.

通过 CancellationToken.None 调用 ExecuteScalarAsync(CancellationToken)Invokes ExecuteScalarAsync(CancellationToken) with CancellationToken.None.

ExecuteScalarAsync(CancellationToken)

这是 ExecuteScalar() 的异步版本。This is the asynchronous version of ExecuteScalar(). 提供程序应使用合适的实现进行重写。Providers should override with an appropriate implementation. 可选择性忽略取消标记。The cancellation token may optionally be ignored.

默认实现调用同步 ExecuteScalar() 方法并返回已完成任务,以便阻止调用线程。The default implementation invokes the synchronous ExecuteScalar() method and returns a completed task, blocking the calling thread. 如果传递到已取消的取消标记,则默认实现将返回已取消的任务。The default implementation will return a cancelled task if passed an already cancelled cancellation token. ExecuteScalar 引发的异常将通过返回的任务异常属性传递。Exceptions thrown by ExecuteScalar will be communicated via the returned Task Exception property.

在返回的任务完成前,不要调用 DbCommand 对象的其他方法和属性。Do not invoke other methods and properties of the DbCommand object until the returned Task is complete.

GetHashCode()

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

(Inherited from Object)
GetLifetimeService()

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

(Inherited from MarshalByRefObject)
GetService(Type)

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

(Inherited from Component)
GetType()

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

(Inherited from Object)
InitializeLifetimeService()

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

(Inherited from MarshalByRefObject)
MemberwiseClone()

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

(Inherited from Object)
MemberwiseClone(Boolean)

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

(Inherited from MarshalByRefObject)
Prepare()

当在派生类中重写时,在数据源上创建准备就绪(或已编译)的命令版本。When overridden in a derived class, creates a prepared (or compiled) version of the command on the data source.

PrepareAsync(CancellationToken)

在数据源上异步创建准备就绪(或已编译)的命令版本。Asynchronously creates a prepared (or compiled) version of the command on the data source.

ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)
ToString()

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

(Inherited from Component)

Events

Disposed

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

(Inherited from Component)

Explicit Interface Implementations

IDbCommand.Connection

获取或设置 IDbCommand 的此实例使用的 IDbConnectionGets or sets the IDbConnection used by this instance of the IDbCommand.

IDbCommand.CreateParameter()

创建 IDbDataParameter 对象的新实例。Creates a new instance of an IDbDataParameter object.

IDbCommand.ExecuteReader()

Connection 执行 CommandText 并生成 IDataReaderExecutes the CommandText against the Connection and builds an IDataReader.

IDbCommand.ExecuteReader(CommandBehavior)

Connection 执行 CommandText,并使用 CommandBehavior 值之一生成 IDataReaderExecutes the CommandText against the Connection, and builds an IDataReader using one of the CommandBehavior values.

IDbCommand.Parameters

获取 IDataParameterCollectionGets the IDataParameterCollection.

IDbCommand.Transaction

获取或设置将在其中执行此 DbCommand 对象的 DbTransactionGets or sets the DbTransaction within which this DbCommand object executes.

Applies to

See also