DbCommand DbCommand DbCommand DbCommand Class

定义

表示要对数据源执行的 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 : System::ComponentModel::Component, IDisposable, System::Data::IDbCommand
public abstract class DbCommand : System.ComponentModel.Component, IDisposable, System.Data.IDbCommand
type DbCommand = class
    inherit Component
    interface IDbCommand
    interface IDisposable
Public MustInherit Class DbCommand
Inherits Component
Implements IDbCommand, IDisposable
继承
派生
实现

构造函数

DbCommand() DbCommand() DbCommand() DbCommand()

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

属性

CanRaiseEvents CanRaiseEvents CanRaiseEvents CanRaiseEvents

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

(Inherited from Component)
CommandText CommandText CommandText CommandText

获取或设置对数据源运行的文本命令。Gets or sets the text command to run against the data source.

CommandTimeout CommandTimeout CommandTimeout CommandTimeout

获取或设置在终止尝试执行命令并生成错误之前的等待时间。Gets or sets the wait time before terminating the attempt to execute a command and generating an error.

CommandType CommandType CommandType CommandType

指示或指定解释 CommandText 属性的方式。Indicates or specifies how the CommandText property is interpreted.

Connection Connection Connection Connection

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

Container Container Container Container

获取 IContainer,它包含 ComponentGets the IContainer that contains the Component.

(Inherited from Component)
DbConnection DbConnection DbConnection DbConnection

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

DbParameterCollection DbParameterCollection DbParameterCollection DbParameterCollection

获取 DbParameter 对象的集合。Gets the collection of DbParameter objects.

DbTransaction DbTransaction DbTransaction DbTransaction

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

DesignMode DesignMode DesignMode DesignMode

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

(Inherited from Component)
DesignTimeVisible DesignTimeVisible DesignTimeVisible DesignTimeVisible

获取或设置一个值,该值指示此命令对象在自定义界面控件中是否可见。Gets or sets a value indicating whether the command object should be visible in a customized interface control.

Events Events Events Events

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

(Inherited from Component)
Parameters Parameters Parameters Parameters

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

Site Site Site Site

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

(Inherited from Component)
Transaction Transaction Transaction Transaction

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

UpdatedRowSource UpdatedRowSource UpdatedRowSource UpdatedRowSource

获取或设置命令结果在由 DataRow 的 Update 方法使用时如何应用于 DbDataAdapterGets or sets how command results are applied to the DataRow when used by the Update method of a DbDataAdapter.

方法

Cancel() Cancel() Cancel() Cancel()

尝试取消 DbCommand 的执行。Attempts to cancels the execution of a DbCommand.

CreateDbParameter() CreateDbParameter() CreateDbParameter() CreateDbParameter()

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

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

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

Dispose() Dispose() Dispose() Dispose()
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)
DisposeAsync() DisposeAsync() DisposeAsync() DisposeAsync()
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

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

(Inherited from Object)
ExecuteDbDataReader(CommandBehavior) ExecuteDbDataReader(CommandBehavior) ExecuteDbDataReader(CommandBehavior) ExecuteDbDataReader(CommandBehavior)

对连接执行命令文本。Executes the command text against the connection.

ExecuteDbDataReaderAsync(CommandBehavior, CancellationToken) ExecuteDbDataReaderAsync(CommandBehavior, CancellationToken) ExecuteDbDataReaderAsync(CommandBehavior, CancellationToken) 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() ExecuteNonQuery() ExecuteNonQuery() ExecuteNonQuery()

对连接对象执行 SQL 语句。Executes a SQL statement against a connection object.

ExecuteNonQueryAsync() ExecuteNonQueryAsync() ExecuteNonQueryAsync() 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) ExecuteNonQueryAsync(CancellationToken) ExecuteNonQueryAsync(CancellationToken) 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() ExecuteReader() ExecuteReader() ExecuteReader()

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

ExecuteReader(CommandBehavior) ExecuteReader(CommandBehavior) ExecuteReader(CommandBehavior) ExecuteReader(CommandBehavior)

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

ExecuteReaderAsync() ExecuteReaderAsync() ExecuteReaderAsync() 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) ExecuteReaderAsync(CancellationToken) ExecuteReaderAsync(CancellationToken) 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) ExecuteReaderAsync(CommandBehavior) ExecuteReaderAsync(CommandBehavior) 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) ExecuteReaderAsync(CommandBehavior, CancellationToken) ExecuteReaderAsync(CommandBehavior, CancellationToken) ExecuteReaderAsync(CommandBehavior, CancellationToken)

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

ExecuteScalar() ExecuteScalar() ExecuteScalar() ExecuteScalar()

执行查询,并返回查询所返回的结果集中第一行的第一列。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() ExecuteScalarAsync() ExecuteScalarAsync() 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) ExecuteScalarAsync(CancellationToken) ExecuteScalarAsync(CancellationToken) 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() GetHashCode() GetHashCode() GetHashCode()

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

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

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

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

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

(Inherited from Object)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

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

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

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

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

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

(Inherited from MarshalByRefObject)
Prepare() Prepare() Prepare() Prepare()

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

PrepareAsync(CancellationToken) PrepareAsync(CancellationToken) PrepareAsync(CancellationToken) PrepareAsync(CancellationToken)
ToString() ToString() ToString() ToString()

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

(Inherited from Component)

显式界面实现

IDbCommand.Connection IDbCommand.Connection IDbCommand.Connection IDbCommand.Connection

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

IDbCommand.CreateParameter() IDbCommand.CreateParameter() IDbCommand.CreateParameter() IDbCommand.CreateParameter()

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

IDbCommand.ExecuteReader() IDbCommand.ExecuteReader() IDbCommand.ExecuteReader() IDbCommand.ExecuteReader()

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

IDbCommand.ExecuteReader(CommandBehavior) IDbCommand.ExecuteReader(CommandBehavior) IDbCommand.ExecuteReader(CommandBehavior) IDbCommand.ExecuteReader(CommandBehavior)

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

IDbCommand.Parameters IDbCommand.Parameters IDbCommand.Parameters IDbCommand.Parameters

获取 IDataParameterCollectionGets the IDataParameterCollection.

IDbCommand.Transaction IDbCommand.Transaction IDbCommand.Transaction IDbCommand.Transaction

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

事件

Disposed Disposed Disposed Disposed

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

(Inherited from Component)

适用于

另请参阅