OdbcCommand.ExecuteReader 方法

定义

CommandText 发送到 Connection 并生成一个 OdbcDataReaderSends the CommandText to the Connection and builds an OdbcDataReader.

重载

ExecuteReader()

CommandText 发送到 Connection 并生成一个 OdbcDataReaderSends the CommandText to the Connection and builds an OdbcDataReader.

ExecuteReader(CommandBehavior)

CommandText 发送到 Connection,并使用 CommandBehavior 值之一构造 OdbcDataReaderSends the CommandText to the Connection, and builds an OdbcDataReader using one of the CommandBehavior values.

ExecuteReader()

CommandText 发送到 Connection 并生成一个 OdbcDataReaderSends the CommandText to the Connection and builds an OdbcDataReader.

public:
 System::Data::Odbc::OdbcDataReader ^ ExecuteReader();
public System.Data.Odbc.OdbcDataReader ExecuteReader ();
override this.ExecuteReader : unit -> System.Data.Odbc.OdbcDataReader
member this.ExecuteReader : unit -> System.Data.Odbc.OdbcDataReader
Public Function ExecuteReader () As OdbcDataReader

返回

一个 OdbcDataReader 对象。An OdbcDataReader object.

注解

应将 CommandText 属性设置为存储过程的完整 ODBC 调用语法。You should set the CommandText property to the full ODBC call syntax for stored procedures. 调用 ExecuteReader时,该命令将执行此存储过程。The command executes this stored procedure when you call ExecuteReader.

使用 OdbcDataReader 时,关联的 OdbcConnection 忙于提供 OdbcDataReaderWhile the OdbcDataReader is used, the associated OdbcConnection is busy serving the OdbcDataReader. 在此状态下,除关闭外,不能对 OdbcConnection 执行任何其他操作。While in this state, no other operations can be performed on the OdbcConnection other than closing it. 在调用 OdbcDataReaderClose 方法之前,会出现这种情况。This is the case until the Close method of the OdbcDataReader is called.

另请参阅

ExecuteReader(CommandBehavior)

CommandText 发送到 Connection,并使用 CommandBehavior 值之一构造 OdbcDataReaderSends the CommandText to the Connection, and builds an OdbcDataReader using one of the CommandBehavior values.

public:
 System::Data::Odbc::OdbcDataReader ^ ExecuteReader(System::Data::CommandBehavior behavior);
public System.Data.Odbc.OdbcDataReader ExecuteReader (System.Data.CommandBehavior behavior);
override this.ExecuteReader : System.Data.CommandBehavior -> System.Data.Odbc.OdbcDataReader
member this.ExecuteReader : System.Data.CommandBehavior -> System.Data.Odbc.OdbcDataReader
Public Function ExecuteReader (behavior As CommandBehavior) As OdbcDataReader

参数

behavior
CommandBehavior

System.Data.CommandBehavior 值之一。One of the System.Data.CommandBehavior values.

返回

一个 OdbcDataReader 对象。An OdbcDataReader object.

注解

如果你希望 SQL 语句仅返回一行,则指定 SingleRow 作为 CommandBehavior 值可能会提高应用程序性能。If you expect your SQL statement to return only a single row, specifying SingleRow as the CommandBehavior value may improve application performance.

应将 CommandText 属性设置为存储过程的完整 ODBC 调用语法。You should set the CommandText property to the full ODBC call syntax for stored procedures. 调用 ExecuteReader时,该命令将执行此存储过程。The command executes this stored procedure when you call ExecuteReader.

OdbcDataReader 支持一种特殊模式,该模式允许有效读取较大的二进制值。The OdbcDataReader supports a special mode that enables large binary values to be read efficiently. 有关详细信息,请参阅 CommandBehaviorSequentialAccess 设置。For more information, see the SequentialAccess setting for CommandBehavior.

备注

CommandBehaviorSequentialAccess 值不是限制设置;这就意味着您将至少具有对 OdbcDataReader的顺序访问。The SequentialAccess value of CommandBehavior is not a limiting setting; it just means that you will have at least sequential access to the OdbcDataReader. 例如,当您在 SequentialAccess 模式下使用 SQL Server ODBC 驱动程序时,仍可以在按顺序读取所有其他列后,转到 OdbcDataReader 行的第一列。For example, when you use the SQL Server ODBC Driver in SequentialAccess mode, you can still move to the first column of an OdbcDataReader row after having read through all the other columns sequentially.

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

另请参阅

适用于