Odbc Provider : ODBC « ADO.Net « C# / CSharp Tutorial






using System;
using System.Data;
using System.Data.Odbc;

    class OdbcProvider
    {
        static void Main(string[] args)
        {
            string connString = @"dsn=northwindodbc";
            string sql = @"select * from employees";
            OdbcConnection conn = null;
            OdbcDataReader reader = null;
            try
            {
                conn = new OdbcConnection(connString);
                conn.Open();

                OdbcCommand cmd = new OdbcCommand(sql, conn);
                reader = cmd.ExecuteReader();
                while (reader.Read())
                {
                    Console.WriteLine("{0} | {1}"
                     , reader["FirstName"].ToString().PadLeft(10)
                     , reader[1].ToString().PadLeft(10)
                    );
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e);
            }
            finally
            {
                reader.Close();
                conn.Close();
            } 
        }
    }








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