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.
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.
51.
myCon.Open();
52.
53.
string
myQuery =
"SELECT * from 社員マスタ"
;
54.
55.
56.
OdbcCommand myCommand =
new
OdbcCommand();
57.
58.
myCommand.CommandText = myQuery;
59.
myCommand.Connection = myCon;
60.
61.
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.
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.
}