Send feedback on this topic.
Teradata.Client.Provider
ExecuteReader(CommandBehavior) Method
Example 



Teradata.Client.Provider Namespace > TdCommand Class > ExecuteReader Method : ExecuteReader(CommandBehavior) Method
One of the Data.CommandBehavior enumerations values. Used to ask for inline LOBs or to close the connection after DataReader is closed.
Executes the SQL statement (TdCommand.CommandText property) using one of the Data.CommandBehavior values.
Syntax
'Declaration
 
Public Overloads Shadows Function ExecuteReader( _
   ByVal behavior As CommandBehavior _
) As TdDataReader
'Usage
 
Dim instance As TdCommand
Dim behavior As CommandBehavior
Dim value As TdDataReader
 
value = instance.ExecuteReader(behavior)
public new TdDataReader ExecuteReader( 
   CommandBehavior behavior
)
public:
new TdDataReader^ ExecuteReader( 
   CommandBehavior behavior
) 

Parameters

behavior
One of the Data.CommandBehavior enumerations values. Used to ask for inline LOBs or to close the connection after DataReader is closed.

Return Value

Returns a TdDataReader object
Exceptions
ExceptionDescription
Indicates the requested behavior is not supported. See the table below.
Can be thrown because of one of the following errors: 1) The TdParameter.Offset is outside of 0 through array size � 1 2) More in-out/out parameters have been specified than returned from the stored procedure.
Indicates one or more parameters cannot be converted to Teradata native types.
The behavior is not one of the System.Data.CommandBehavior enumeration members.
Can be thrown because of one of the following errors: 1) TdConnection is not in Open state or is null. 2) The local transaction associated with TdCommand is not the same local transaction associated with the TdConnection --assign local transaction to TdCommand.Transaction property. 3) TdCommand.CommandText is null or empty.
The TdCommand is closed / disposed.
Can be thrown because of one of the following errors: 1) Teradata returned an error. 2) The Data Provider detected an error.
Remarks

Executes a SQL statement and returns a static forward-only result set (TdDataReader).

When TdCommand.CommandType is set to StoredProcedure, any output parameters are populated with data. If the stored procedure does not return a dynamic result set, the resulting TdDataReader contains no rows.

Refer to Returning Data of Output Parameters in a Result Set for more information on the execution of stored procedures.

The .NET Data Provider allows more than one TdDataReader object to be open at any given time for each TdConnection. However, there can only be one TdDataReader for each TdCommand. TdDataReader must be closed before TdCommand can execute another SQL statement.

The .NET Data Provider supports In-Line and Deferred LOB retrievals. By default LOBs are retrieved in deferred mode. If the SequentialAccess bit of behavior is turned on, LOBs are retrieved in Inline mode.

behavior can be set to a bit-wise combination of the following CommandBehavior values:

CommandBehavior Member Name Description
CloseConnection The associated TdConnection object is closed when the TdDataReader instance is closed.
Default Sets no CommandBehavior flags. Calling ExecuteReader(CommandBehavior.Default) is equivalent to calling ExecuteReader().
KeyInfo Not supported.
SchemaOnly The SQL statement is prepared and the resulting TdDataReader is used to retrieve schema information (TdDataReader.GetSchemaTable). TdDataReader.Read will return false (no rows).
SequentialAccess When set, LOBs are returned in-line and they can only be accessed sequentially. See the Advanced SQL Engine documentation for additional information about Inline mode vs. Deferred mode.
SingleResult The SQL statement returns a single result set. Data.IDataReader.NextResult will return false.
SingleRow SingleRow does not result in any internal optimization. However, TdDataReader.Read returns false after the first row is read in each result set.
Example
The following example creates a TdConnection and executes a SQL statement. It returns a TdDataReader. When the calling method closes the TdDataReader, the corresponding TdConnection is closed.
public TdDataReader ExecuteQuery(string connectionString, string commandText)
{
    TdConnection cn = new TdConnection(connectionString);
    cn.Open();
    
    TdCommand cmd = new TdCommand(commandText, cn);
    TdDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
            
    return reader;
}
Requirements

Target Platforms: Windows 8.1, Windows 10, Windows Server 2012 R2, Windows Server 2016, Windows Server 2019

See Also

Reference

TdCommand Class
TdCommand Members
Overload List