By using this site, you acknowledge that you have read and understand our Cookie policy, Privacy policy and Terms .
close

Tutorials and informations about Teradata.

rss_feed Subscribe RSS

In this post, I will demonstrate how to connect to Teradata database via .NET Data Provider for Teradata using C#.

Prerequisites

Install the .NET Data Provider for Teradata from the following link:

Teradata Tools and Utilities Windows Installation Package

Step 1 Create a Console Project

Name it as’' ‘ConsoleApps.Teradata’.

Add reference to library ‘.NET Data Provider for Teradata’ as shown in the following screenshot:

image

The version in my PC is 14.11.0.1. You can always download the latest version from Teradata official site.

Step 2 Create a method to read data from Teradata

Remember to import the namespace ‘Teradata.Client.Provider’.

using System;
using Teradata.Client.Provider;

namespace ConsoleApps.Teradata
{
    class Program
    {
        static void Main(string[] args)
        {
            DisplayEmployeeInfoFromTeraData();
            Console.ReadLine();

        }

        private static void DisplayEmployeeInfoFromTeraData()
        {
        }
    }
}

Step 3 Implement the method

Create connection, command and adapter objects to read data in a standard ADO.NET way.

The sample code will be similar to what I’ve provided here:

private static void DisplayEmployeeInfoFromTeraData()
        {
            var employeeData = new DataSet();

            var connectionString = "Data Source=192.168.121.128;User ID=dbc;Password=dbc;";
            using (var connection = new TdConnection(connectionString))
            {
                var sql = @"SELECT Emp.EmployeeID,
    Emp.EmployeeName,
    
    CASE
        WHEN  Emp.Gendar = 'M' THEN 'Dear MR ' || Emp.EmployeeName ELSE 'Dear MS ' ||Emp.EmployeeName
    END AS ""Employee Salutation""
    FROM TD_MS_SAMPLE_DB.Employee Emp; ";
                var command = new TdCommand(sql, connection);
                var adapter = new TdDataAdapter(command);
                connection.Open();
                adapter.Fill(employeeData);
                connection.Close();

            }

            DisplayEmployeeData(employeeData);
        }

        private static void DisplayEmployeeData(DataSet employeeData)
        {
            if (employeeData.Tables != null && employeeData.Tables.Count > 0)
            {
                var employees = employeeData.Tables[0];
                var columnCount = employees.Columns.Count;
                foreach (DataRow row in employees.Rows)
                {
                    for (int i = 0; i < columnCount; i++)
                    {
                        var col = employees.Columns[i];
                        Console.WriteLine("{0} = {1}", col.ColumnName, row[i]);   
                    }
                    Console.WriteLine();
                }
                Console.WriteLine("{0} Records", employees.Rows.Count);
            }
        }

In this sample, I am connecting to a local Teradata virtual machine with address as ‘192.168.121.128’. One thing to notice is that all the class names are prefixed with ‘Td’, e.g. Connection class is named TdConnection, Command class is named TdCommand and so forth.

Step 4 The result

image

Summary

Teradata is used in many data warehousing projects. If you really wants to use it in your OLTP projects, you can connect to it via .NET Data Provider for Teradata or ODBC Teradata provider. The syntax will be similar as connecting to SQL Server, Oracle or any other databases supported by ADO.NET.

info Last modified by Raymond at 4 months ago * This page is subject to Site terms.

info About author

More from Kontext

Machine Learning with .NET in Jupyter Notebooks

local_offer machine-learning local_offer jupyter-notebook local_offer C# local_offer dotnet core

visibility 159
thumb_up 0
access_time 2 months ago

In this article, I'm going to show you how to install Jupyter in Windows and then install .NET kernel for Jupyter notebooks. It also shows a machine learning example using ML.NET. The target audience are .NET developers who want to expand their skills in data engineering and science domain...

open_in_new View

local_offer teradata local_offer SQL

visibility 38
thumb_up 0
access_time 4 months ago

This code snippet shows how to calculate time differences.

open_in_new View

local_offer teradata local_offer spark local_offer pyspark

visibility 1789
thumb_up 0
access_time 8 months ago

In my article Connect to Teradata database through Python , I demonstrated about how to use Teradata python package or Teradata ODBC driver to connect to Teradata. In this article, I’m going to...

open_in_new View

local_offer teradata local_offer SQL

visibility 67
thumb_up 0
access_time 4 months ago

JSON is commonly used in modern applications for data storage and transfers. Pretty much all programming languages provide APIs to parse JSON. 

open_in_new View

comment Comments (2)

comment Add comment

Please log in or register to comment. account_circle Log in person_add Register
account_circle Raymond
@Neuwa Rakgajane There will be no much difference whether you want to query from one table or from multiple. You can refer to ADO.NET to understand all the operations you can do with Teradata .Net Data Provider. https://msdn.microsoft.com/en-us/library/e80y5yhx(v=vs.110).aspx In terms of writing complex SQL query, I was planning to create a serial about querying Teradata but have not completed yet. http://kosmisch.net/Blog/DataAndBusinessIntelligence/Archive/2015/5/3/querying-teradata-and-sql-server-tutorial-1-the-select-statement.html
format_quote

person Neuwa Rakgajane access_time 4 years ago
Re:[C#] Connect to Teradata Database via .NET Data Provider

I have been doing the your tutorial on teradata. Aren't there more tutorial where you query multiple tables at once? I wanted to get a practice on those. Please send me a link if you have such tutorial. I mean more advanced queries, your tutorial were so easy to understand, I need such other complex example urgently.
reply Reply
account_circle Neuwa Rakgajane
I have been doing the your tutorial on teradata. Aren't there more tutorial where you query multiple tables at once? I wanted to get a practice on those. Please send me a link if you have such tutorial. I mean more advanced queries, your tutorial were so easy to understand, I need such other complex example urgently.
reply Reply
Kontext Column

Kontext Column

Created for everyone to publish data, programming and cloud related articles. Follow three steps to create your columns.

Learn more arrow_forward
info Follow us on Twitter to get the latest article updates. Follow us