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



Teradata.Client.Provider Namespace > TdCommand Class > ExecuteReader Method : ExecuteReader() Method
Executes the SQL statement (TdCommand.CommandText property) and returns a TdDataReader object.
Syntax
'Declaration
 
Public Overloads Shadows Function ExecuteReader() As TdDataReader
'Usage
 
Dim instance As TdCommand
Dim value As TdDataReader
 
value = instance.ExecuteReader()
public new TdDataReader ExecuteReader()
public:
new TdDataReader^ ExecuteReader(); 

Return Value

Returns a TdDataReader object.
Exceptions
ExceptionDescription
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.
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 Transaction property. 3) TdCommand.CommandText is null or empty.
The TdCommand is closed / disposed.
Can be thrown because of the one of the following errors: 1) Teradata returned an error or 2) The Data Provider detected an error.
Remarks

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

When a stored procedure is executed by setting the TdCommand.CommandText to the stored procedure's name, and the TdCommand.CommandType is set to System.Data.CommandType.StoredProcedure the provider performs the following tasks:

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 to be open at any given time per TdConnection instance. However, there can only be one TdDataReader per TdCommand. TdDataReader must be closed before TdCommand can execute another SQL statement.

Example
The following example creates a TdConnection and executes a SQL statement. An instance of TdDataReader is returned. The calling method must close the TdDataReader and the corresponding connection (cn.Close()).
public TdDataReader ExecuteQuery(string connectionString, string commandText, 
                                 out TdConnection cn)
{
    cn = new TdConnection(connectionString);
    cn.Open();
            
    TdCommand cmd = new TdCommand(commandText, cn);
    TdDataReader reader = cmd.ExecuteReader();
            
    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