親フォルダ
01.using System;
02.using System.Data.Odbc;
03. 
04.namespace MySQL
05.{
06.    class Program
07.    {
08.        static void Main(string[] args)
09.        {
10.            // データベースのユーザを入力する( root )
11.            Console.Write("ユーザ :");
12.            string user = Console.ReadLine();
13.            Console.WriteLine(user);
14. 
15.            // 接続文字列を作成するオブジェクト
16.            OdbcConnectionStringBuilder builder = new OdbcConnectionStringBuilder();
17. 
18.            // HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI
19.            // HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\ODBC\ODBCINST.INI
20.            // MySQL ODBC 5.3 Unicode Driver
21. 
22.            // 接続文字列を作成する為の情報を渡す
23.            builder.Driver = "MySQL ODBC 5.3 Unicode Driver";
24.            builder.Add("SERVER", "localhost");
25.            builder.Add("DATABASE", "lightbox");
26.            builder.Add("UID", user);
27.            builder.Add("PWD", "");
28. 
29.            Console.WriteLine(builder.ConnectionString);
30. 
31.            // 接続用のオブジェクト
32.            OdbcConnection myCon = new OdbcConnection();
33. 
34.            // 接続用のオブジェクトに接続文字列を渡す
35.            myCon.ConnectionString = builder.ConnectionString;
36. 
37.            try
38.            {
39.                // DB の接続
40.                myCon.Open();
41. 
42.                string myQuery = "SELECT 社員マスタ.*,DATE_FORMAT(生年月日,'%Y-%m-%d') as 誕生日 from 社員マスタ";
43. 
44.                // SELECT 実行用のオブジェクトを作成
45.                OdbcCommand myCommand = new OdbcCommand();
46.                // 実行する為に必要な情報をセット
47.                myCommand.CommandText = myQuery;
48.                myCommand.Connection = myCon;
49. 
50.                // 実行後にレコードセットを取得する為のオブジェクトを作成
51.                OdbcDataReader myReader;
52.                // ここで SELECT を実行してその結果をオブジェクトに格納する
53.                myReader = myCommand.ExecuteReader();
54. 
55.                while (myReader.Read())
56.                {
57.                    // 番号による列データの取り出し
58.                    string fld1 = myReader.GetValue(0).ToString();
59.                    string fld2 = myReader.GetValue(1).ToString();
60.                    Console.WriteLine($"番号:{fld1} {fld2}");
61. 
62.                    // 列名による取り出し
63.                    string col1 = "社員コード";
64.                    string col2 = "氏名";
65. 
66.                    int no1 = myReader.GetOrdinal(col1);
67.                    int no2 = myReader.GetOrdinal(col2);
68. 
69.                    fld1 = myReader.GetValue(no1).ToString();
70.                    fld2 = myReader.GetValue(no2).ToString();
71.                    Console.WriteLine($"列名:{fld1} {fld2}");
72.                }
73. 
74. 
75.                myCommand.Dispose();
76. 
77.                // 接続を閉じる
78.                myCon.Close();
79.            }
80.            catch (Exception ex)
81.            {
82. 
83.                Console.WriteLine(ex.Message);
84.            }
85. 
86.            // 接続オブジェクトを廃棄する
87.            myCon.Dispose();
88. 
89. 
90.            Console.ReadLine();
91.        }
92.    }
93.}