Send feedback on this topic.
Teradata.Client.Provider
RecordsReturned Property
Example 



Teradata.Client.Provider Namespace > TdDataReader Class : RecordsReturned Property
Gets the number of rows returned from the execution of a SELECT statement.
Syntax
'Declaration
 
Public ReadOnly Property RecordsReturned As Integer
'Usage
 
Dim instance As TdDataReader
Dim value As Integer
 
value = instance.RecordsReturned
public int RecordsReturned {get;}
public:
property int RecordsReturned {
   int get();
}

Property Value

The records returned from a select statement
Remarks
The RecordsReturned property reflects the activity count of a SELECT statement. The activity count is the number of rows selected. For all other statements this property will be 0.

If the number of rows returned from the execution of select statement overflows Int32.MaxValue, Int32.MaxValue value will be returned. The provider will post an event to TdConnection.InfoMessage when an overflow condition occurs. The event will include a warning code and message. The warning message will have the actual number of records returned. The message code is 114003 and the message text is "An overflow occurred while calculating the number of records returned, actual value is [RecordsReturned]"

NOTE: In order for an application to be aware that an overflow occurred, it must register for the callback with TdConnection.InfoMessage event.

This property is not cumulative. If multiple SELECT statements are contained in a multi-statement request, the RecordsReturned will only contain the activity count of the current result set.
Example

The following example creates a TdConnection, sets up the TdConnection.InfoMessage event and executes a SQL statement.

When TdDataReader.RecordsReturned is used and if the number of records returned overflows Int32.MaxValue, Int32.MaxValue is returned and a warning message with the actual records returned is exposed through the TdConnection InfoMessage event.

When TdDataReader.RecordsReturned64 is used and if the number of records returned overflows Int64.MaxValue, Int64.MaxValue is returned and a warning message with the actual records returned is exposed through the TdConnection InfoMessage event.

// This method is invoked when the TdConnection.InfoMessage is fired.
public void OnInfoMessage(Object sender, TdInfoMessageEventArgs i)
{
    // The TdConnection.InfoMessage event gets fired when the records returned
    // overflows Int32.MaxValue for RecordsReturned and when the records returned
    // overflows Int64.MaxValue for RecordsReturned64. The actual number of
    // records returned can be extracted from the message as below. 
    if( i.Errors[0].Number == 114003 )
    {
        Decimal recordsReturned = 
                  Convert.ToDecimal(i.Message.Split('[')[3].Split(']')[0]);
    
        Console.WriteLine("Actual records returned is : ", recordsReturned);
    }
}
             
public void ExecuteDataReader(string connectionString, string commandText)
{
    // Open a session to Teradata
    TdConnection cn = new TdConnection(connectionString);
    
    // Setting up the event 
    cn.InfoMessage += new TdInfoMessageEventHandler(this.OnInfoMessage);
    
    cn.Open();
            
    // Execute the command
    TdCommand cmd = new TdCommand(commandText, cn);
    TdDataReader reader = cmd.ExecuteReader();
    Console.WriteLine("{0} records returned.", reader.RecordsReturned);
 
    // Close the command and session
    reader.close();
    cmd.Dispose();
    cn.Close();
            
}
Requirements

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

See Also

Reference

TdDataReader Class
TdDataReader Members