ADO.NET Provider for Teradata

Build 24.0.9060

Querying with the DataReader

The CData ADO.NET Provider for Teradata implements two ADO.NET interfaces you can use to retrieve data from Teradata: TeradataDataAdapter and TeradataDataReader objects. Whereas TeradataDataAdapter objects retrieve a single result set of all the data that matches a query, TeradataDataReader objects fetch data in subset increments as needed.

Using the TeradataDataReader

The TeradataDataReader retrieves data faster than the TeradataDataAdapter because it can retrieve data in pages. As you read data from the TeradataDataReader, it periodically requests the next page of results from the data source, if required. This causes results to be returned at a faster rate. The following example selects all the columns from the "CData"."dbo".NorthwindProducts table:

C#

string connectionString = "User=Admin;Password=test123;Database=Northwind;DataSource=127.0.0.1";

using (TeradataConnection connection = new TeradataConnection(connectionString)) {
  TeradataCommand cmd = new TeradataCommand("SELECT * FROM \"CData\".\"dbo\".NorthwindProducts", connection);
  
  TeradataDataReader rdr = cmd.ExecuteReader();

  while (rdr.Read()) {
    Console.WriteLine(String.Format("\t{0} --> \t\t{1}", rdr["ProductId"], rdr["ProductName"]));
  }
}

VB.NET

Dim connectionString As String = "User=Admin;Password=test123;Database=Northwind;DataSource=127.0.0.1"

Using connection As New TeradataConnection(connectionString)
  Dim cmd As New TeradataCommand("SELECT * FROM \"CData\".\"dbo\".NorthwindProducts", connection)

  Dim rdr As TeradataDataReader = cmd.ExecuteReader()

  While rdr.Read()
    Console.WriteLine([String].Format(vbTab & "{0} --> " & vbTab & vbTab & "{1}", rdr("ProductId"), rdr("ProductName")))
  End While
End Using

Copyright (c) 2024 CData Software, Inc. - All rights reserved.
Build 24.0.9060