To use the .NET Data Provider for Teradata, you need to do the following:
- Add a reference in your project to the Teradata.Client.Provider.dll assembly.
- Add an
imports or using statement for Teradata.Client.Provider namespace in your code.
- Read the documentation for the following core objects to get familiar with the .NET Data Provider for Teradata.
| Object |
Description |
| TdConnection |
- Establishes a connection to the Teradata Vantage and provides implicit and explicit transaction control.
- Factory for TdCommand objects.
|
| TdCommand |
- Executes parameterized and non-parameterize SQL statements.
- Maps .NET data types to Vantage data types (Parameters).
- Factory for TdDataReader objects.
|
| TdDataReader |
- Exposes the result set (spool file) as a static forward-only cursor.
- Maps Vantage data types to .NET data types.
|
| TdDataAdapter |
- Uses TdDataReader to fill a DataSet.
- Applies changes to the DataSet back to the Advanced SQL Engine.
|
Example
The Hello World example below illustrates making a Connection to Vantage and executing "Select Date" using the TdDataReader.
- Create a C# Console project.
- Open the "Program.cs" file, Copy and Paste the below code into your file.
- Remember to Add a reference in your project to the Teradata.Client.Provider.dll assembly.
- Change the Data Source, User ID and Password on the "TdConnection" line of code listed below.
- Build the project.
| C# |
Copy Code |
using System;
using System.Collections.Generic;
using System.Text;
using Teradata.Client.Provider;
namespace Teradata.Client.Provider.HelloWorld
{
class HelloWorld
{
static void Main(string[] args)
{
using (TdConnection cn = new TdConnection("Data Source = x;User ID = y;Password = z;"))
{
cn.Open();
TdCommand cmd = cn.CreateCommand();
cmd.CommandText = "SELECT DATE";
using (TdDataReader reader = cmd.ExecuteReader())
{
reader.Read();
DateTime date = reader.GetDate(0);
Console.WriteLine("Teradata Database DATE is {0}", date);
}
}
}
}
} |
Note |
| You can find more Coding Examples at <Installation-Directory>\Samples\LearningExamples directory. |
See Also
Accessing Data
ADO.NET