Saturday, December 1, 2018

Sample C# Code connection to NetSuite ODBC

Connect to NetSuite ODBC using C#

Requirement:

- DSN connection to NetSuite


using System;
using System.Data.Odbc;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            //Create your ODBC query
            string query = "SELECT * FROM EMPLOYEES WHERE EMPLOYEES.COUNTRY='US'";

            //Create the connection
            OdbcConnection conn = new OdbcConnection("dsn=NetSuite; uid=bruce@banner.com; pwd=Passw0rd");

            OdbcCommand comm = new OdbcCommand(query, conn);
            comm.CommandTimeout = 0;

            //Establish the connection to database
            conn.Open();
            Console.WriteLine("Connection Successful!\n");

            //Retrieve the results
            OdbcDataReader reader = comm.ExecuteReader();
            while (reader.Read())
            {
                //Display the results
                Console.WriteLine("Employee Full Name = {0}", reader[17]);
            }
            Console.ReadLine();
        }
    }
}

No comments:

Post a Comment