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

取得包含 IContainerComponentGets 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

取得或設定 DbTransaction,此 DbCommand 物件會在其中執行。Gets 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

取得或設定 DbTransaction,此 DbCommand 物件會在其中執行。Gets 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)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。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 擲回的例外狀況會透過傳回的 Task Exception 屬性來傳送。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,該版本會針對 CommandText 執行 Connection,並傳回 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,該版本會針對 CommandText 執行 Connection,並傳回 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,該版本會針對 CommandText 執行 Connection,並傳回 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()

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。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 的淺層複本 (Shallow Copy)。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 名稱的 StringReturns 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

取得或設定 DbTransaction,此 DbCommand 物件會在其中執行。Gets 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)

適用於

另請參閱