親フォルダ
01.using System;
02.using System.Collections.Generic;
03.using System.ComponentModel;
04.using System.Data;
05.using System.Data.Odbc;
06.using System.Drawing;
07.using System.Linq;
08.using System.Text;
09.using System.Threading.Tasks;
10.using System.Windows.Forms;
11. 
12.namespace BuildField
13.{
14.    public partial class Form1 : Form
15.    {
16.        // 単独
17.        //private TextBox textBox1;
18.        // 配列
19.        private TextBox[] textBoxArray;
20. 
21.        public Form1()
22.        {
23.            InitializeComponent();
24.            controlInit();
25.        }
26. 
27.        private void controlInit()
28.        {
29.            // 接続文字列を作成するオブジェクト
30.            OdbcConnectionStringBuilder builder = new OdbcConnectionStringBuilder();
31. 
32.            // 接続文字列を作成する為の情報を渡す
33.            builder.Driver = "MySQL ODBC 5.3 Unicode Driver";
34.            builder.Add("SERVER", "localhost");
35.            builder.Add("DATABASE", "lightbox");
36.            builder.Add("UID", "root");
37.            builder.Add("PWD", "");
38. 
39.            // 接続用のオブジェクト
40.            OdbcConnection myCon = new OdbcConnection();
41. 
42.            // 接続用のオブジェクトに接続文字列を渡す
43.            myCon.ConnectionString = builder.ConnectionString;
44. 
45.            // 実行後にレコードセットを取得する為のオブジェクトを作成
46.            OdbcDataReader myReader;
47. 
48.            try
49.            {
50.                // DB の接続
51.                myCon.Open();
52. 
53.                string myQuery = "SELECT * from 社員マスタ";
54. 
55.                // SELECT 実行用のオブジェクトを作成
56.                OdbcCommand myCommand = new OdbcCommand();
57.                // 実行する為に必要な情報をセット
58.                myCommand.CommandText = myQuery;
59.                myCommand.Connection = myCon;
60. 
61.                // ここで SELECT を実行してその結果をオブジェクトに格納する
62.                myReader = myCommand.ExecuteReader();
63. 
64.            }
65.            catch (Exception ex)
66.            {
67.                return;
68.            }
69. 
70.            int fieldCount = myReader.FieldCount;
71. 
72.            textBoxArray = new TextBox[fieldCount];
73. 
74.            for (int i = 0; i < fieldCount; i++) {
75.                // インスタンス作成
76.                textBoxArray[i] = new TextBox();
77.                // フォント設定
78.                textBoxArray[i].Font = new Font("MS UI Gothic", 12F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(128)));
79.                // 位置設定
80.                textBoxArray[i].Location = new Point(208, 42 + i * 35);
81.                // 名称設定
82.                textBoxArray[i].Name = "textBox"+(i+1);
83.                // 幅と高さの設定
84.                textBoxArray[i].Size = new Size(208, 23);
85.                // TAB の順序
86.                textBoxArray[i].TabIndex = i;
87. 
88.                Controls.Add(textBoxArray[i]);
89.            }
90. 
91.            myReader.Close();
92.            myCon.Close();
93.            myCon.Dispose();
94. 
95.        }
96.    }
97.}