Connecting to an ODBC Data Source : ODBC « ADO.Net « C# / CSharp Tutorial






using System;
using System.Data.Odbc;

    class Program
    {
        static void Main(string[] args)
        {
            string odbcConnectString = "DRIVER={SQL Server};SERVER=(local);" +
                "DATABASE=AdventureWorks;Trusted_Connection=yes;";

            string sqlSelect = "SELECT TOP 5 Title, FirstName, LastName FROM Person.Contact";

            using (OdbcConnection connection =new OdbcConnection(odbcConnectString))
            {
                OdbcCommand command = new OdbcCommand(sqlSelect, connection);

                connection.Open(  );
                OdbcDataReader reader = command.ExecuteReader(  );

                while (reader.Read(  ))
                    Console.WriteLine("{0} {1}", reader[0], reader[1]);
            }
       }
    }








32.48.ODBC
32.48.1.Creating Connection To ODBC
32.48.2.Connecting to a Text File
32.48.3.Connecting to an ODBC Data Source
32.48.4.Connect to SqlServer using OdbcConnection
32.48.5.Odbc Provider