CommandBehavior 列舉

定義

提供查詢結果的描述及其對資料庫的影響。Provides a description of the results of the query and its effect on the database.

此列舉具有 FlagsAttribute 個屬性允許以位元方式合併其成員值。

public enum class CommandBehavior
[System.Flags]
public enum CommandBehavior
type CommandBehavior = 
Public Enum CommandBehavior
繼承
CommandBehavior
屬性

欄位

CloseConnection 32

當命令執行時,相關聯的 Connection 物件會在相關聯的 DataReader 物件關閉時關閉。When the command is executed, the associated Connection object is closed when the associated DataReader object is closed.

Default 0

要求可能傳回多個結果集 (Result Set)。The query may return multiple result sets. 執行查詢可能會影響資料庫狀態。Execution of the query may affect the database state. Default 設定為沒有 CommandBehavior 旗標,所以呼叫 ExecuteReader(CommandBehavior.Default) 在功能上相當於呼叫 ExecuteReader()Default sets no CommandBehavior flags, so calling ExecuteReader(CommandBehavior.Default) is functionally equivalent to calling ExecuteReader().

KeyInfo 4

查詢會傳回資料行和主索引鍵資訊。The query returns column and primary key information. 提供者會將額外資料行附加到現有主索引鍵和時間戳記資料行的結果集中。The provider appends extra columns to the result set for existing primary key and timestamp columns.

SchemaOnly 2

查詢只會傳回資料行資訊。The query returns column information only. 當使用 SchemaOnly 時,.NET Framework Data Provider for SQL Server 會優先於使用 SET FMTONLY ON 執行的陳述式。When using SchemaOnly, the .NET Framework Data Provider for SQL Server precedes the statement being executed with SET FMTONLY ON.

SequentialAccess 16

提供方法來讓 DataReader 使用大型二進位值來處理含有資料行的資料列。Provides a way for the DataReader to handle rows that contain columns with large binary values. SequentialAccess 並不會載入整個資料列,而是啟用 DataReader 來載入資料做為資料流。Rather than loading the entire row, SequentialAccess enables the DataReader to load data as a stream. 然後您可以使用 GetBytesGetChars 方法來指定要開始讀取作業的位元組位置和所傳回資料的限制緩衝區大小。You can then use the GetBytes or GetChars method to specify a byte location to start the read operation, and a limited buffer size for the data being returned.

SingleResult 1

查詢傳回單一結果集。The query returns a single result set.

SingleRow 8

查詢預期會傳回第一個結果集的單一資料列。The query is expected to return a single row of the first result set. 執行查詢可能會影響資料庫狀態。Execution of the query may affect the database state. 某些 .NET Framework 資料提供者可以使用這項資訊來最佳化命令的效能,但並不一定需要使用。Some .NET Framework data providers may, but are not required to, use this information to optimize the performance of the command. 當您使用 SingleRow 物件的 ExecuteReader() 方法來指定 OleDbCommand 時,.NET Framework Data Provider for OLE DB 會使用 OLE DB IRow 介面 (如果可用) 來執行繫結。When you specify SingleRow with the ExecuteReader() method of the OleDbCommand object, the .NET Framework Data Provider for OLE DB performs binding using the OLE DB IRow interface if it is available. 否則,它會使用 IRowset 介面。Otherwise, it uses the IRowset interface. 如果 SQL 陳述式預期只會傳回單一資料列,則指定 SingleRow 也可以增進應用程式效能。If your SQL statement is expected to return only a single row, specifying SingleRow can also improve application performance. 在執行預期會傳回多個結果集的要求時,可能指定 SingleRowIt is possible to specify SingleRow when executing queries that are expected to return multiple result sets. 在這種情況下,也就是同時指定多結果集 SQL 查詢及單一資料列時,傳回的結果將只會包含第一個結果集中的第一個資料列,In that case, where both a multi-result set SQL query and single row are specified, the result returned will contain only the first row of the first result set. 而不會傳回查詢的其他結果集。The other result sets of the query will not be returned.

備註

CommandBehavior ExecuteReader 方法IDbCommand會使用這些值, 以及任何執行中的類別。The CommandBehavior values are used by the ExecuteReader method of IDbCommand and any implementing classes.

您可以使用這些值的位元組合。A bitwise combination of these values may be used.

CommandBehavior在用來定義SqlNotificationRequestSqlDependency時, 會忽略, 因此不應使用。CommandBehavior is ignored when used to define a SqlNotificationRequest or SqlDependency and should therefore not be used. 在這兩種情況下, 請CommandBehavior使用不需要參數的函數。Use the constructor that does not require a CommandBehavior parameter in these two cases.

個別列舉成員的注意事項Notes on individual enumeration members

使用KeyInfo時, SQL Server 的 .NET Framework Data Provider 會在使用SET FMTONLY OFFSET NO_BROWSETABLE ON執行的語句之前。When using KeyInfo, the .NET Framework Data Provider for SQL Server precedes the statement being executed with SET FMTONLY OFF and SET NO_BROWSETABLE ON. 使用者應該留意可能的副作用, 例如使用SET FMTONLY ON語句時的干擾。The user should be aware of potential side effects, such as interference with the use of SET FMTONLY ON statements. 如需詳細資訊,請參閱 SET FMTONLY (Transact-SQL)For more information, see SET FMTONLY (Transact-SQL).

注意

SequentialAccess來取出大數值和二進位資料。Use SequentialAccess to retrieve large values and binary data. 否則, OutOfMemoryException可能會發生, 而且連接將會關閉。Otherwise, an OutOfMemoryException might occur and the connection will be closed.

當您指定SequentialAccess時, 您必須以傳回的順序讀取資料行, 但您不需要讀取每個資料行。When you specify SequentialAccess, you are required to read from the columns in the order they are returned, although you are not required to read each column. 一旦您讀取了傳回的資料資料流程中的某個位置之後, 就無法再從DataReader該位置讀取或之前的資料。Once you have read past a location in the returned stream of data, data at or before that location can no longer be read from the DataReader. 當您使用OleDbDataReader時, 可以重新讀取目前的資料行值, 直到讀取它為止。When using the OleDbDataReader, you can reread the current column value until reading past it. 使用SqlDataReader時, 您只能讀取資料行值一次。When using the SqlDataReader, you can read a column value only once.

適用於