IDbCommand.ExecuteReader 方法

定义

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

重载

ExecuteReader()

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

ExecuteReader(CommandBehavior)

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

ExecuteReader()

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

public:
 System::Data::IDataReader ^ ExecuteReader();
public System.Data.IDataReader ExecuteReader ();
abstract member ExecuteReader : unit -> System.Data.IDataReader
Public Function ExecuteReader () As IDataReader

返回

IDataReader 对象。An IDataReader object.

ExecuteReader(CommandBehavior)

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

public:
 System::Data::IDataReader ^ ExecuteReader(System::Data::CommandBehavior behavior);
public System.Data.IDataReader ExecuteReader (System.Data.CommandBehavior behavior);
abstract member ExecuteReader : System.Data.CommandBehavior -> System.Data.IDataReader
Public Function ExecuteReader (behavior As CommandBehavior) As IDataReader

参数

behavior
CommandBehavior

CommandBehavior 值之一。One of the CommandBehavior values.

返回

IDataReader 对象。An IDataReader object.

注解

调用方必须调用 Connection 属性的 Open 方法。The caller must call the Open method of the Connection property.

CommandType 属性设置为 StoredProcedure时,CommandText 属性应设置为存储过程的名称。When the CommandType property is set to StoredProcedure, the CommandText property should be set to the name of the stored procedure. 调用 ExecuteReader时,该命令将执行此存储过程。The command executes this stored procedure when you call ExecuteReader.

备注

使用 SequentialAccess 检索大值和二进制数据。Use SequentialAccess to retrieve large values and binary data. 否则,可能会发生 OutOfMemoryException 并且连接将关闭。Otherwise, an OutOfMemoryException might occur and the connection will be closed.

如果 IDataReader 正在使用中,则关联的 IDbConnection 忙于提供 IDataReaderWhile the IDataReader is in use, the associated IDbConnection is busy serving the IDataReader. 在此状态下,除关闭外,不能对 IDbConnection 执行任何其他操作。While in this state, no other operations can be performed on the IDbConnection other than closing it. 在调用 DataReader 的 Close 方法之前,会出现这种情况。This is the case until the Close method of the DataReader is called. 如果在 CommandBehavior 设置为 CloseConnection的情况下创建 DataReader,则关闭 DataReader 会自动关闭连接。If the DataReader is created with CommandBehavior set to CloseConnection, closing the DataReader closes the connection automatically.

适用于