DbCommand 類別

定義

表示要針對資料來源執行的 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 物件的執行個體。Constructs an instance of the DbCommand object.

屬性

CanRaiseEvents

取得值,指出元件是否能引發事件。Gets a value indicating whether the component can raise an event.

(繼承來源 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.

(繼承來源 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.

(繼承來源 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.

(繼承來源 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.

(繼承來源 Component)
Transaction

取得或設定 DbTransaction,此 DbCommand 物件會在其中執行。Gets or sets the DbTransaction within which this DbCommand object executes.

UpdatedRowSource

當覆寫衍生類別時,取得或設定當 DbDataAdapter 的 Update 方法使使用 DataRow 時,命令結果的套用方式。When 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.

方法

Cancel()

當覆寫衍生類別時,嘗試取消執行 DbCommandWhen 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)

建立包含所有相關資訊的物件,這些資訊是產生用來與遠端物件通訊的所需 Proxy。Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object.

(繼承來源 MarshalByRefObject)
CreateParameter()

建立 DbParameter 物件的新執行個體。Creates a new instance of a DbParameter object.

Dispose()
Dispose(Boolean)
DisposeAsync()

非同步地處置命令物件。Asynchronously diposes the command object.

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 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 擲回的例外狀況會透過傳回的 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()

當覆寫衍生類別時,對連線物件執行 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,該版本會針對 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)

非同步版本的 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)

非同步版本的 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)

叫用 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.

(繼承來源 Object)
GetLifetimeService()

擷取控制這個執行個體存留期 (Lifetime) 原則的目前存留期服務物件。Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(繼承來源 MarshalByRefObject)
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)
InitializeLifetimeService()

取得存留期服務物件,以控制這個執行個體的存留期原則。Obtains a lifetime service object to control the lifetime policy for this instance.

(繼承來源 MarshalByRefObject)
MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(繼承來源 Object)
MemberwiseClone(Boolean)

建立目前 MarshalByRefObject 物件的淺層複本。Creates a shallow copy of the current MarshalByRefObject object.

(繼承來源 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()

傳回任何包含 Component 名稱的 StringReturns a String containing the name of the Component, if any. 不應覆寫此方法。This method should not be overridden.

(繼承來源 Component)

事件

Disposed

當此元件由 Dispose() 方法的呼叫處置時發生。Occurs when the component is disposed by a call to the Dispose() method.

(繼承來源 Component)

明確介面實作

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

取得或設定 DbTransaction,此 DbCommand 物件會在其中執行。Gets or sets the DbTransaction within which this DbCommand object executes.

適用於

另請參閱