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

执行命令时,关闭关联的 DataReader 对象时,关联的 Connection 对象也会关闭。When the command is executed, the associated Connection object is closed when the associated DataReader object is closed.

Default 0

查询可能返回多个结果集。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 时,用于 SQL Server 的 .NET Framework 数据提供程序在要执行的语句前加上 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. 使用 OleDbCommand 对象的 ExecuteReader() 方法指定 SingleRow 时,用于 OLE DB 的 .NET Framework 数据提供程序使用 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.

注解

值由的IDbCommand方法和任何实现类使用。 ExecuteReader CommandBehaviorThe 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 数据提供程序优先于正在使用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.

适用于