OdbcCommand.ExecuteReader 方法
定义
将 CommandText 发送到 Connection 并生成一个 OdbcDataReader。Sends the CommandText to the Connection and builds an OdbcDataReader.
重载
| ExecuteReader() |
将 CommandText 发送到 Connection 并生成一个 OdbcDataReader。Sends the CommandText to the Connection and builds an OdbcDataReader. |
| ExecuteReader(CommandBehavior) |
将 CommandText 发送到 Connection,并使用 |
ExecuteReader()
将 CommandText 发送到 Connection 并生成一个 OdbcDataReader。Sends 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 正忙于为提供服务 OdbcDataReader 。While 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. 在调用的方法之前,会出现这种情况 Close OdbcDataReader 。This is the case until the Close method of the OdbcDataReader is called.
适用于
ExecuteReader(CommandBehavior)
将 CommandText 发送到 Connection,并使用 CommandBehavior 值之一构造 OdbcDataReader。Sends 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. 有关详细信息,请参阅的 SequentialAccess 设置 CommandBehavior 。For more information, see the SequentialAccess setting for CommandBehavior.
备注
的 SequentialAccess 值 CommandBehavior 不是限制设置; 它只是表示你将至少具有对的顺序访问 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. 例如,当您在模式下使用 SQL Server ODBC 驱动程序时 SequentialAccess ,仍可以在 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 正忙于为提供服务 OdbcDataReader 。While 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.