質問編集履歴

1

追記させていただきました。エラーが出てしまい方向性はあってるのでしょうか?

2020/03/31 14:30

投稿

pj7577bm60v
pj7577bm60v

スコア13

test CHANGED
File without changes
test CHANGED
@@ -92,6 +92,188 @@
92
92
 
93
93
  }
94
94
 
95
+
96
+
97
+ //追記させていただきました。
98
+
99
+ using System;
100
+
101
+ using System.Collections.Generic;
102
+
103
+ using System.ComponentModel;
104
+
105
+ using System.Data;
106
+
107
+ using System.Drawing;
108
+
109
+ using System.Linq;
110
+
111
+ using System.Text;
112
+
113
+ using System.Threading.Tasks;
114
+
115
+ using System.Windows.Forms;
116
+
117
+ using System.Data.SqlClient;
118
+
119
+
120
+
121
+ namespace WindowsFormsApp4
122
+
123
+ {
124
+
125
+ public partial class Form1 : Form
126
+
127
+ {
128
+
129
+ private SqlConnection cn = new SqlConnection();
130
+
131
+ private SqlCommand cmd = new SqlCommand();
132
+
133
+ private SqlDataReader rd;
134
+
135
+ private String cnstr = @"Data Source=(LocalDB)\MSSQLLocalDB;" + @"AttachDbFilename=|DataDirectory|\Schedule2.mdf;" + "Integrated Security = True; Connect Timeout = 30";
136
+
137
+ private string name = "";
138
+
139
+ private DateTime date = new DateTime(2000, 1, 1);
140
+
141
+ private string task = "";
142
+
143
+
144
+
145
+ readonly List<ListBox> listBoxs;
146
+
147
+
148
+
149
+ public Form1()
150
+
151
+ {
152
+
153
+ InitializeComponent();
154
+
155
+
156
+
157
+ listBoxs = new List<ListBox>
158
+
159
+ {
160
+
161
+ null,
162
+
163
+ listBox1,
164
+
165
+ listBox2,
166
+
167
+ listBox3,
168
+
169
+ listBox4,
170
+
171
+ listBox5,
172
+
173
+ listBox6,
174
+
175
+ listBox7,
176
+
177
+ listBox8,
178
+
179
+ listBox9,
180
+
181
+ listBox10,
182
+
183
+ listBox11,
184
+
185
+ listBox12,
186
+
187
+ listBox13,
188
+
189
+ listBox14
190
+
191
+ };
192
+
193
+ }
194
+
195
+
196
+
197
+ private void button1_Click(object sender, EventArgs e)
198
+
199
+ {
200
+
201
+
202
+
203
+ cn.ConnectionString = cnstr;
204
+
205
+ cn.Open();
206
+
207
+
208
+
209
+ cmd.Connection = cn;
210
+
211
+ cmd.CommandType = CommandType.Text;
212
+
213
+ cmd.CommandText = "SELECT * FROM [dbo] . [Table]";
214
+
215
+
216
+
217
+ rd = cmd.ExecuteReader();
218
+
219
+ while (rd.Read())
220
+
221
+ {
222
+
223
+ name = Convert.ToString(rd["名前"]);
224
+
225
+ date = Convert.ToDateTime(rd["日付"]);
226
+
227
+ task = Convert.ToString(rd["タスクネーム"]);
228
+
229
+
230
+
231
+ if (name == "A")
232
+
233
+ {
234
+
235
+ var listBox = listBoxs[ListBoxItems];
236
+
237
+ //listBox.Items.Add = task;
238
+
239
+ }
240
+
241
+
242
+
243
+ }
244
+
245
+ rd.Close();
246
+
247
+ cn.Close();
248
+
249
+ }
250
+
251
+
252
+
253
+ private int ListBoxItems
254
+
255
+ {
256
+
257
+
258
+
259
+ get
260
+
261
+ {
262
+
263
+ //if (date ==3,1 ) return 1;
264
+
265
+
266
+
267
+ return 0;
268
+
269
+ }
270
+
271
+ }
272
+
273
+ }
274
+
275
+ }
276
+
95
277
  ```
96
278
 
97
279