Send feedback on this topic.
Teradata.Client.Provider
Accessor Methods for Retrieving Data
.NET Data Provider for Teradata > Developer's Guide > Data Types > Accessor Methods for Retrieving Data

The TdDataReader class is a forward-only result set with Base Class Library (BCL) and Provider Specific accessor methods. Data Source agnostic .NET applications utilize accessor methods in System.Data.Common.DbDataReader class which is the base class for the TdDataReader class. The DbDataReader accessor methods return BCL types, for example System.Int32, System.DateTime and System.String. The Provider Specific accessor methods return types unique to the .NET Data Provider for Teradata.

The following tables shows the Advanced SQL Engine data type and the corresponding TdDataReader accessor methods. The TdDataReader class implements the DbDataReader methods that are listed in the "TdDataReader BCL Accessor Methods" column in addition to the Provider Specific accessor methods. The first value listed in the BCL Type column corresponds to the Type returned by GetFieldType method. The first value listed in the Provider specific Type column corresponds to the Type returned by GetProviderSpecificFieldType method.

In addition, the generic method GetFieldValue<T> may be used with any BCL or Provider Specific type [T] to return the value as that type. 

Note

The Data Provider returns a BCL Type if it does not have a Provider Specific Type. For example GetProviderSpecificValue method returns a boxed System.Int32 because the Data Provider does not have an Integer Provider Specific Type.

Note

The Data Provider can convert most of the SQL types to Sytem.String data type. For example it can convert a SQL Timestamp data type to System.String.

SQL
Type
Provider Specific
Type
TdDataReader
Provider Specific
Accessor Methods
BCL Type TdDataReader
BCL
Accessor Methods
Character and CLOB Data Types Char     String
Char[]
TextReader
GetString
GetChars
GetTextReader
Clob TdClob GetTdClob String
Char[]
TextReader
GetString
GetChars
GetTextReader
Graphic     String
Char[]
GetString
GetChars
JSON TdClob GetTdClob String
Char[]
TextReader
GetString
GetChars
GetTextReader
VarChar     String
Char[]
TextReader
GetString
GetChars
GetTextReader
VarGraphic     String
Char[]
GetString
GetChars
XML TdXml GetTdXml String
Char[]
XmlReader
GetString
GetChars
GetXmlReader
Byte and BLOB Data Types Blob TdBlob GetTdBlob Byte[]
Stream
GetBytes
GetStream
Byte   Byte[]
Stream
GetBytes
GetStream
VarByte     Byte[]
Stream
GetBytes
GetStream
Numeric Data Types BigInt Int64
String
GetInt64
GetString
ByteInt     Int16
String
GetInt16
GetString
Decimal TdDecimal GetTdDecimal Decimal
String
GetDecimal
GetString
Double     Double
String
GetDouble
GetString
Integer     Int32
String
GetInt32
GetString
Number TdNumber GetTdNumber Double
String
GetDouble
GetString
SmallInt   Int16
String
GetInt16
GetString
Date and Time Data Types Date TdDate
DateTime
GetTdDate
GetDate
DateTime
String
GetDateTime
GetString
Time TdTime
TimeSpan
GetTdTime
GetTime
TimeSpan
String
GetValue
GetString
Time With Time Zone TdTimeWithTimeZone GetTdTimeWithTimeZone String GetString
Timestamp TdTimestamp GetTdTimestamp DateTime
String
GetDateTime
GetString
Timestamp With Time Zone TdTimestampWithTimeZone
DateTimeOffset
GetTdTimestampWithTimeZone
GetDateTimeOffset
DateTimeOffset
String
GetValue
GetString
Interval Data Types Interval Day TdIntervalDay
TimeSpan
GetTdIntervalDay
GetTimeSpan
TimeSpan
String
GetValue
GetString
Interval Day To Hour TdIntervalDayToHour
TimeSpan
GetTdIntervalDayToHour
GetTimeSpan
TimeSpan
String
GetValue
GetString
Interval Day To Minute TdIntervalDayToMinute
TimeSpan
GetTdIntervalDayToMinute
GetTimeSpan
TimeSpan
String
GetValue
GetString
Interval Day To Second TdIntervalDayToSecond
TimeSpan
GetTdIntervalDayToSecond
GetTimeSpan
TimeSpan
String
GetValue
GetString
Interval Hour TdIntervalHour
TimeSpan
GetTdIntervalHour
GetTimeSpan
TimeSpan
String
GetValue
GetString
Interval Hour To Minute TdIntervalHourToMinute
TimeSpan
GetTdIntervalHourToMinute
GetTimeSpan
TimeSpan
String
GetValue
GetString
Interval Hour To Second TdIntervalHourToSecond
TimeSpan
GetTdIntervalHourToSecond
GetTimeSpan
TimeSpan
String
GetValue
GetString
Interval Minute TdIntervalMinute
TimeSpan
GetTdIntervalMinute
GetTimeSpan
TimeSpan
String
GetValue
GetString
Interval Minute To Second TdIntervalMinuteToSecond
TimeSpan
GetTdIntervalMinuteToSecond
GetTimeSpan
TimeSpan
String
GetValue
GetString
Interval Second TdIntervalSecond
TimeSpan
GetTdIntervalSecond
GetTimeSpan
TimeSpan
String
GetValue
GetString
Interval Year TdIntervalYear GetTdIntervalYear
String GetString
Interval Year To Month TdIntervalYearToMonth GetTdIntervalYearToMonth
String GetString
Interval Month TdIntervalMonth GetTdIntervalMonth String GetString
Period Data Types Period(Date) TdPeriodDate GetTdPeriodDate String GetString
Period(Time) TdPeriodTime GetTdPeriodTime String GetString
Period(Time With Time Zone) TdPeriodTimeWithTimeZone GetTdPeriodTimeWithTimeZone String GetString
Period(Timestamp) TdPeriodTimestamp GetTdPeriodTimestamp String GetString
Period(Timestamp With Time Zone) TdPeriodTimestampWithTimeZone GetTdPeriodTimestampWithTimeZone String GetString
Note

TdDataReader class does not have accessor methods for User Defined Types (UDT), User Defined Array Types and Geospatial Types. The SQL Engine transforms the aforementioned types to and from predefined SQL types.

Note

The data of a Number column may get rounded to 15 digits if TdDataReader.GetDouble is called to retrieve the data. The reason for this is that a System.Double has a precision of 15 digits. A Teradata Number type can have a precision of up to 38 digits. To retrieve the Number in its entirety, use TdDataReader.GetTdNumber.

The following example shows how to retrieve the BCL and Provider Specific type declaration.

C#
Copy Code
using (TdConnection cn = new TdConnection("data source=x;UserId=y;Password=z;"))
{
    cn.Open();
    TdCommand cmd = cn.CreateCommand();
    cmd.CommandText = "SELECT " +
        "CAST('col #1' as Char(10)) as colChar, 'col #2' as colVarChar, " +
        "CAST('col #3' as Clob(1000)) as colClob," +
        "'c1c0'XBF as colByte, 'c1c1'XBV as colVarByte, CAST('c1c2'XBF as Blob(1000)) as colBlob," +
        "'1'XI1 as colByteInt, '2'XI2 as colSmallInt, '3'XI4 as colInteger, '4'XI8 as colBigInt," +
        "38.20 as colDecimal, 1E10 as colDouble," +
        "DATE'2011-01-01' as colDate, Time'15:30:00' as colTime, " +
        "TIME'10:37:12-08:00' as colTimeWithTimeZone, Timestamp'2006-11-23 15:30:23' as colTimestamp," +
        "TIMESTAMP '2002-01-01 10:37:12-08:00' as colTimestampWithTimeZone, " +
        "INTERVAL -'2' YEAR as colIntervalYear, INTERVAL '2-06' YEAR TO MONTH as colIntervalYearToMonth," +
        "INTERVAL '6' MONTH as colIntervalMonth, INTERVAL -'30' DAY as colIntervalDay, " +
        "INTERVAL '1 12' DAY TO HOUR as colIntervalDayToHour, " +
        "INTERVAL '30 12:30' DAY TO MINUTE as colIntervalDayToMinute, " +
        "INTERVAL '30 12:30:30.5' DAY TO SECOND as colIntervalDayToSecond, " +
        "INTERVAL '2000' HOUR as colIntervalHour, " +
        "INTERVAL '12:37' HOUR TO MINUTE as colIntervalHourToMinute, " +
        "INTERVAL '12:37:12.123456' HOUR TO SECOND as colIntervalHourToSecond," +
        "INTERVAL '600' MINUTE as colIntervalMinute, " +
        "INTERVAL '9:30' MINUTE TO SECOND as colIntervalMinuteToSecond, " +
        "INTERVAL '0.000001' SECOND as colIntervalSecond," +
        "PERIOD '(2005-02-03, 2006-02-04)' as colPeriodDate, " +
        "PERIOD '(08:00:00, 15:40:00)' as colPeriodTime,  " +
        "PERIOD '(08:00:00-08:00, 15:40:00-05:00)' as colPeriodTimeWithTimeZone, " +
        "PERIOD'(2011-01-01 10:00:00, 2011-02-01 00:00:00)' as colPeriodTimestamp, " +
        "PERIOD'(2011-01-01 10:00:00-08:00, 2011-02-01 00:00:00-08:00)' as colPeriodTimestampWithTimeZone";

    using (TdDataReader reader = cmd.ExecuteReader())
    {
        if (reader.HasRows)
        {
            Console.WriteLine("{0,-35} {1,-30} {2}\n\r", @"Column Name", @"BCL Type", @"Provider Specific Type");
            for (Int32 ordinal = 0; ordinal < reader.FieldCount; ordinal++)
            {
                Console.WriteLine("{0,-35} {1,-30} {2}",
                    reader.GetName(ordinal),
                    reader.GetFieldType(ordinal),
                    reader.GetProviderSpecificFieldType(ordinal) );
            }
        }
    }
}
/*
Column Name                         BCL Type                       Provider Specific Type
colChar                             System.String                  System.String
colVarChar                          System.String                  System.String
colClob                             System.String                  Teradata.Client.Provider.TdClob
colByte                             System.Byte[]                  System.Byte[]
colVarByte                          System.Byte[]                  System.Byte[]
colBlob                             System.Byte[]                  Teradata.Client.Provider.TdBlob
colByteInt                          System.Int16                   System.Int16
colSmallInt                         System.Int16                   System.Int16
colInteger                          System.Int32                   System.Int32
colBigInt                           System.Int64                   System.Int64
colDecimal                          System.Decimal                 Teradata.Client.Provider.TdDecimal
colDouble                           System.Double                  System.Double
colDate                             System.DateTime                Teradata.Client.Provider.TdDate
colTime                             System.TimeSpan                Teradata.Client.Provider.TdTime
colTimeWithTimeZone                 System.String                  Teradata.Client.Provider.TdTimeWithTimeZone
colTimestamp                        System.DateTime                Teradata.Client.Provider.TdTimestamp
colTimestampWithTimeZone            System.DateTimeOffset          Teradata.Client.Provider.TdTimestampWithTimeZone
colIntervalYear                     System.String                  Teradata.Client.Provider.TdIntervalYear
colIntervalYearToMonth              System.String                  Teradata.Client.Provider.TdIntervalYearToMonth
colIntervalMonth                    System.String                  Teradata.Client.Provider.TdIntervalMonth
colIntervalDay                      System.TimeSpan                Teradata.Client.Provider.TdIntervalDay
colIntervalDayToHour                System.TimeSpan                Teradata.Client.Provider.TdIntervalDayToHour
colIntervalDayToMinute              System.TimeSpan                Teradata.Client.Provider.TdIntervalDayToMinute
colIntervalDayToSecond              System.TimeSpan                Teradata.Client.Provider.TdIntervalDayToSecond
colIntervalHour                     System.TimeSpan                Teradata.Client.Provider.TdIntervalHour
colIntervalHourToMinute             System.TimeSpan                Teradata.Client.Provider.TdIntervalHourToMinute
colIntervalHourToSecond             System.TimeSpan                Teradata.Client.Provider.TdIntervalHourToSecond
colIntervalMinute                   System.TimeSpan                Teradata.Client.Provider.TdIntervalMinute
colIntervalMinuteToSecond           System.TimeSpan                Teradata.Client.Provider.TdIntervalMinuteToSecond
colIntervalSecond                   System.TimeSpan                Teradata.Client.Provider.TdIntervalSecond
colPeriodDate                       System.String                  Teradata.Client.Provider.TdPeriodDate
colPeriodTime                       System.String                  Teradata.Client.Provider.TdPeriodTime
colPeriodTimeWithTimeZone           System.String                  Teradata.Client.Provider.TdPeriodTimeWithTimeZone
colPeriodTimestamp                  System.String                  Teradata.Client.Provider.TdPeriodTimestamp
colPeriodTimestampWithTimeZone      System.String                  Teradata.Client.Provider.TdPeriodTimestampWithTimeZone
*/