質問編集履歴

2

修正

2021/04/13 00:51

投稿

natume4948
natume4948

スコア9

test CHANGED
File without changes
test CHANGED
@@ -68,306 +68,306 @@
68
68
 
69
69
  {
70
70
 
71
+ //▼変数定義
72
+
73
+ string id = "";
74
+
75
+ string music = "";
76
+
77
+ string artist = "";
78
+
79
+ string album = "";
80
+
81
+ string date = "";
82
+
83
+ string genre = "";
84
+
85
+ DialogResult result;
86
+
87
+ DataTable dataT = new DataTable();
88
+
89
+ //テキストボックスのテキスト用配列
90
+
91
+ string[] search = new string[6];
92
+
93
+ //項目名用配列
94
+
95
+ string[] yourName = { "MusicID", "MusicName", "ArtistName", "AlbumName", "ReleaseDate", "Genre" };
96
+
97
+ //▲変数定義
98
+
99
+ //▼メソッド定義
100
+
101
+ //SQL文作成メソッド
102
+
103
+ void Sql(int index, string sq)
104
+
105
+ {
106
+
107
+ search[index] = sq;
108
+
109
+ //全体で使用する基本のSQL、1=1はAND処理を楽にするため
110
+
111
+ string sql = "SELECT * FROM music WHERE 1 = 1";
112
+
113
+ //string sql = "SELECT * FROM music WHERE 1 = 1 AND CAST(TRACK_NO AS VARCHAR) LIKE '1%'";
114
+
115
+ for (int i = 0; i < search.Length; i++)
116
+
117
+ {
118
+
119
+ string sea = search[i];
120
+
121
+ //トラックナンバー用処理
122
+
123
+ if (i == 0)
124
+
125
+ {
126
+
127
+ //前方一致処理
128
+
129
+ sql += " AND " + "CAST(" + yourName[i] + " AS VARCHAR) LIKE '" + sea + "%'";
130
+
131
+ }
132
+
133
+ //リリース用処理
134
+
135
+ else if (i == 4)
136
+
137
+ {
138
+
139
+ //後方一致処理
140
+
141
+ sql += " AND " + "CAST(" + yourName[i] + " AS VARCHAR) LIKE '%" + sea + "'";
142
+
143
+ }
144
+
145
+ else
146
+
147
+ {
148
+
149
+ //部分一致処理
150
+
151
+ sql += " AND " + yourName[i] + " LIKE '%" + sea + "%'";
152
+
153
+ }
154
+
155
+ }
156
+
157
+ Debug.WriteLine("xxxxxxxxxxxxxxxxx");
158
+
159
+ Debug.WriteLine(sql);
160
+
161
+ Debug.WriteLine("xxxxxxxxxxxxxxxxx");
162
+
163
+ //データベース描画前に一度削除
164
+
165
+ dataGridView1.DataSource = "";
166
+
167
+ //sql文エラーに備えて
168
+
169
+ try
170
+
171
+ {
172
+
173
+ //SQL文実行処理
174
+
175
+ SqlConnection sqlconn = new SqlConnection(Properties.Settings.Default.sqlserver);
176
+
177
+ SqlCommand command = new SqlCommand(sql, sqlconn);
178
+
179
+ SqlDataAdapter adapter = new SqlDataAdapter(command);
180
+
181
+ DataTable dt = new DataTable();
182
+
183
+ adapter.Fill(dt);
184
+
185
+ //データベースをGridに渡して表示
186
+
187
+ dataGridView1.DataSource = dt;
188
+
189
+ dataT = dt;
190
+
191
+ //検索結果の件数を表示
192
+
193
+ int count = dt.Rows.Count;
194
+
195
+ label1.Text = count.ToString();
196
+
197
+ }
198
+
199
+ catch (Exception ex)
200
+
201
+ {
202
+
203
+ //エラー表示
204
+
205
+ MessageBox.Show(ex.ToString());
206
+
207
+ }
208
+
209
+ }
210
+
71
211
 
72
212
 
213
+ public Form1()
214
+
215
+ {
216
+
217
+ InitializeComponent();
218
+
219
+ }
220
+
221
+
222
+
223
+ private void Form1_Load(object sender, EventArgs e)
224
+
225
+ {
226
+
227
+ //maxとminを同じにすることでサイズ固定
228
+
229
+ this.MaximumSize = this.Size;
230
+
231
+ this.MinimumSize = this.Size;
232
+
233
+ //最大化・最小化無効
234
+
235
+ this.MaximizeBox = false;
236
+
237
+ this.MinimizeBox = false;
238
+
239
+ SqlConnection sqlconn = new SqlConnection(Properties.Settings.Default.sqlserver);
240
+
241
+ sqlconn.Open();
242
+
243
+ SqlCommand command = new SqlCommand("SELECT * from Musics", sqlconn);
244
+
245
+ SqlDataAdapter adapter = new SqlDataAdapter(command);
246
+
247
+ DataTable dt = new DataTable();
248
+
249
+ adapter.Fill(dt);
250
+
251
+ dataGridView1.DataSource = dt;
252
+
253
+ dataT = dt;
254
+
255
+ //検索結果の件数を表示
256
+
257
+ int count = dt.Rows.Count;
258
+
259
+ label1.Text = count.ToString();
260
+
261
+ }
262
+
263
+
264
+
265
+
266
+
267
+ private void textBox1_TextChanged(object sender, EventArgs e)
268
+
269
+ {
270
+
271
+ id = textBox1.Text;
272
+
273
+ //値の種類とテキストボックスと項目名を渡す
274
+
275
+ Sql(0, id);
276
+
277
+ }
278
+
279
+
280
+
281
+ private void textBox2_TextChanged(object sender, EventArgs e)
282
+
283
+ {
284
+
285
+ music = textBox2.Text;
286
+
287
+ Sql(1, music);
288
+
289
+ }
290
+
291
+
292
+
293
+ private void textBox3_TextChanged(object sender, EventArgs e)
294
+
295
+ {
296
+
297
+ artist = textBox3.Text;
298
+
299
+ Sql(2, artist);
300
+
301
+ }
302
+
303
+
304
+
305
+ private void textBox4_TextChanged(object sender, EventArgs e)
306
+
307
+ {
308
+
309
+ album = textBox4.Text;
310
+
311
+ Sql(3, album);
312
+
313
+
314
+
315
+ }
316
+
317
+
318
+
319
+ private void textBox5_TextChanged(object sender, EventArgs e)
320
+
321
+ {
322
+
323
+ date = textBox5.Text;
324
+
325
+ Sql(4, date);
326
+
327
+
328
+
329
+ }
330
+
331
+
332
+
333
+ private void textBox6_TextChanged(object sender, EventArgs e)
334
+
335
+ {
336
+
337
+ genre = textBox6.Text;
338
+
339
+ Sql(5, genre);
340
+
341
+ }
342
+
343
+
344
+
345
+ private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
346
+
347
+ {
348
+
349
+
350
+
351
+ }
352
+
353
+
354
+
355
+ private void button1_Click(object sender, EventArgs e)
356
+
357
+ {
358
+
359
+ //ダイアログのYesNoを取得
360
+
361
+ MessageBox.Show("一覧データを出力しますか?", "出力の確認", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
362
+
363
+ MessageBox.Show("一覧データを出力しました");
364
+
365
+
366
+
367
+ }
368
+
73
369
 
74
370
 
75
- public Form1()
76
-
77
- {
78
-
79
- InitializeComponent();
80
-
81
- }
82
-
83
-
84
-
85
- private void Form1_Load(object sender, EventArgs e)
86
-
87
- {
88
-
89
- //maxとminを同じにすることでサイズ固定
90
-
91
- this.MaximumSize = this.Size;
92
-
93
- this.MinimumSize = this.Size;
94
-
95
- //最大化・最小化無効
96
-
97
- this.MaximizeBox = false;
98
-
99
- this.MinimizeBox = false;
100
-
101
- SqlConnection sqlconn = new SqlConnection(Properties.Settings.Default.sqlserver);
102
-
103
- sqlconn.Open();
104
-
105
- SqlCommand command = new SqlCommand("SELECT * from Musics", sqlconn);
106
-
107
- SqlDataAdapter adapter = new SqlDataAdapter(command);
108
-
109
- DataTable dt = new DataTable();
110
-
111
- adapter.Fill(dt);
112
-
113
- dataGridView1.DataSource = dt;
114
-
115
- dataT = dt;
116
-
117
- //検索結果の件数を表示
118
-
119
- int count = dt.Rows.Count;
120
-
121
- label1.Text = count.ToString();
122
-
123
- }
124
-
125
-
126
-
127
-
128
-
129
- private void textBox1_TextChanged(object sender, EventArgs e)
130
-
131
- {
132
-
133
- id = textBox1.Text;
134
-
135
- //値の種類とテキストボックスと項目名を渡す
136
-
137
- Sql(0, id);
138
-
139
- }
140
-
141
-
142
-
143
- private void textBox2_TextChanged(object sender, EventArgs e)
144
-
145
- {
146
-
147
- music = textBox2.Text;
148
-
149
- Sql(1, music);
150
-
151
- }
152
-
153
-
154
-
155
- private void textBox3_TextChanged(object sender, EventArgs e)
156
-
157
- {
158
-
159
- artist = textBox3.Text;
160
-
161
- Sql(2, artist);
162
-
163
- }
164
-
165
-
166
-
167
- private void textBox4_TextChanged(object sender, EventArgs e)
168
-
169
- {
170
-
171
- album = textBox4.Text;
172
-
173
- Sql(3, album);
174
-
175
-
176
-
177
- }
178
-
179
-
180
-
181
- private void textBox5_TextChanged(object sender, EventArgs e)
182
-
183
- {
184
-
185
- date = textBox5.Text;
186
-
187
- Sql(4, date);
188
-
189
-
190
-
191
- }
192
-
193
-
194
-
195
- private void textBox6_TextChanged(object sender, EventArgs e)
196
-
197
- {
198
-
199
- genre = textBox6.Text;
200
-
201
- Sql(5, genre);
202
-
203
- }
204
-
205
-
206
-
207
- private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
208
-
209
- {
210
-
211
-
212
-
213
- }
214
-
215
-
216
-
217
- private void button1_Click(object sender, EventArgs e)
218
-
219
- {
220
-
221
- //▼変数定義
222
-
223
- string id = "";
224
-
225
- string music = "";
226
-
227
- string artist = "";
228
-
229
- string album = "";
230
-
231
- string date = "";
232
-
233
- string genre = "";
234
-
235
- DialogResult result;
236
-
237
- DataTable dataT = new DataTable();
238
-
239
- //テキストボックスのテキスト用配列
240
-
241
- string[] search = new string[6];
242
-
243
- //項目名用配列
244
-
245
- string[] yourName = { "MusicID", "MusicName", "ArtistName", "AlbumName", "ReleaseDate", "Genre" };
246
-
247
- //▲変数定義
248
-
249
- //▼メソッド定義
250
-
251
- //SQL文作成メソッド
252
-
253
- void Sql(int index, string sq)
254
-
255
- {
256
-
257
- search[index] = sq;
258
-
259
- //全体で使用する基本のSQL、1=1はAND処理を楽にするため
260
-
261
- string sql = "SELECT * FROM music WHERE 1 = 1";
262
-
263
- //string sql = "SELECT * FROM music WHERE 1 = 1 AND CAST(TRACK_NO AS VARCHAR) LIKE '1%'";
264
-
265
- for (int i = 0; i < search.Length; i++)
266
-
267
- {
268
-
269
- string sea = search[i];
270
-
271
- //トラックナンバー用処理
272
-
273
- if (i == 0)
274
-
275
- {
276
-
277
- //前方一致処理
278
-
279
- sql += " AND " + "CAST(" + yourName[i] + " AS VARCHAR) LIKE '" + sea + "%'";
280
-
281
- }
282
-
283
- //リリース用処理
284
-
285
- else if (i == 4)
286
-
287
- {
288
-
289
- //後方一致処理
290
-
291
- sql += " AND " + "CAST(" + yourName[i] + " AS VARCHAR) LIKE '%" + sea + "'";
292
-
293
- }
294
-
295
- else
296
-
297
- {
298
-
299
- //部分一致処理
300
-
301
- sql += " AND " + yourName[i] + " LIKE '%" + sea + "%'";
302
-
303
- }
304
-
305
- }
306
-
307
- Debug.WriteLine("xxxxxxxxxxxxxxxxx");
308
-
309
- Debug.WriteLine(sql);
310
-
311
- Debug.WriteLine("xxxxxxxxxxxxxxxxx");
312
-
313
- //データベース描画前に一度削除
314
-
315
- dataGridView1.DataSource = "";
316
-
317
- //sql文エラーに備えて
318
-
319
- try
320
-
321
- {
322
-
323
- //SQL文実行処理
324
-
325
- SqlConnection sqlconn = new SqlConnection(Properties.Settings.Default.sqlserver);
326
-
327
- SqlCommand command = new SqlCommand(sql, sqlconn);
328
-
329
- SqlDataAdapter adapter = new SqlDataAdapter(command);
330
-
331
- DataTable dt = new DataTable();
332
-
333
- adapter.Fill(dt);
334
-
335
- //データベースをGridに渡して表示
336
-
337
- dataGridView1.DataSource = dt;
338
-
339
- dataT = dt;
340
-
341
- //検索結果の件数を表示
342
-
343
- int count = dt.Rows.Count;
344
-
345
- label1.Text = count.ToString();
346
-
347
- }
348
-
349
- catch (Exception ex)
350
-
351
- {
352
-
353
- //エラー表示
354
-
355
- MessageBox.Show(ex.ToString());
356
-
357
- }
358
-
359
- }
360
-
361
- //ダイアログのYesNoを取得
362
-
363
- result = MessageBox.Show("一覧データを出力しますか?", "出力の確認", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
364
-
365
- MessageBox.Show("一覧データを出力しました");
366
-
367
- }
368
-
369
-
370
-
371
371
 
372
372
 
373
373
  private void label1_Click(object sender, EventArgs e)
@@ -382,6 +382,8 @@
382
382
 
383
383
  }
384
384
 
385
+
386
+
385
387
  ```
386
388
 
387
389
 

1

誤字

2021/04/13 00:51

投稿

natume4948
natume4948

スコア9

test CHANGED
File without changes
test CHANGED
@@ -68,448 +68,306 @@
68
68
 
69
69
  {
70
70
 
71
- //▼変数定義
72
-
73
- string id = "";
74
-
75
- string music = "";
76
-
77
- string artist = "";
78
-
79
- string album = "";
80
-
81
- string date = "";
82
-
83
- string genre = "";
84
-
85
- DialogResult result;
86
-
87
- DataTable dataT = new DataTable();
88
-
89
- //テキストボックスのテキスト用配列
90
-
91
- string[] search = new string[6];
92
-
93
- //項目名用配列
94
-
95
- string[] yourName = { "MusicID", "MusicName", "ArtistName", "AlbumName", "ReleaseDate", "Genre" };
96
-
97
- //▲変数定義
98
-
99
- //▼メソッド定義
100
-
101
- //SQL文作成メソッド
102
-
103
- private void Sql(int index, string sq)
104
-
105
- {
106
-
107
- search[index] = sq;
108
-
109
- //全体で使用する基本のSQL、1=1はAND処理を楽にするため
110
-
111
- string sql = "SELECT * FROM music WHERE 1 = 1";
112
-
113
- //string sql = "SELECT * FROM music WHERE 1 = 1 AND CAST(TRACK_NO AS VARCHAR) LIKE '1%'";
114
-
115
- for (int i = 0; i < search.Length; i++)
71
+
72
+
73
+
74
+
75
+ public Form1()
76
+
77
+ {
78
+
79
+ InitializeComponent();
80
+
81
+ }
82
+
83
+
84
+
85
+ private void Form1_Load(object sender, EventArgs e)
86
+
87
+ {
88
+
89
+ //maxとminを同じにすることでサイズ固定
90
+
91
+ this.MaximumSize = this.Size;
92
+
93
+ this.MinimumSize = this.Size;
94
+
95
+ //最大化・最小化無効
96
+
97
+ this.MaximizeBox = false;
98
+
99
+ this.MinimizeBox = false;
100
+
101
+ SqlConnection sqlconn = new SqlConnection(Properties.Settings.Default.sqlserver);
102
+
103
+ sqlconn.Open();
104
+
105
+ SqlCommand command = new SqlCommand("SELECT * from Musics", sqlconn);
106
+
107
+ SqlDataAdapter adapter = new SqlDataAdapter(command);
108
+
109
+ DataTable dt = new DataTable();
110
+
111
+ adapter.Fill(dt);
112
+
113
+ dataGridView1.DataSource = dt;
114
+
115
+ dataT = dt;
116
+
117
+ //検索結果の件数を表示
118
+
119
+ int count = dt.Rows.Count;
120
+
121
+ label1.Text = count.ToString();
122
+
123
+ }
124
+
125
+
126
+
127
+
128
+
129
+ private void textBox1_TextChanged(object sender, EventArgs e)
130
+
131
+ {
132
+
133
+ id = textBox1.Text;
134
+
135
+ //値の種類とテキストボックスと項目名を渡す
136
+
137
+ Sql(0, id);
138
+
139
+ }
140
+
141
+
142
+
143
+ private void textBox2_TextChanged(object sender, EventArgs e)
144
+
145
+ {
146
+
147
+ music = textBox2.Text;
148
+
149
+ Sql(1, music);
150
+
151
+ }
152
+
153
+
154
+
155
+ private void textBox3_TextChanged(object sender, EventArgs e)
156
+
157
+ {
158
+
159
+ artist = textBox3.Text;
160
+
161
+ Sql(2, artist);
162
+
163
+ }
164
+
165
+
166
+
167
+ private void textBox4_TextChanged(object sender, EventArgs e)
168
+
169
+ {
170
+
171
+ album = textBox4.Text;
172
+
173
+ Sql(3, album);
174
+
175
+
176
+
177
+ }
178
+
179
+
180
+
181
+ private void textBox5_TextChanged(object sender, EventArgs e)
182
+
183
+ {
184
+
185
+ date = textBox5.Text;
186
+
187
+ Sql(4, date);
188
+
189
+
190
+
191
+ }
192
+
193
+
194
+
195
+ private void textBox6_TextChanged(object sender, EventArgs e)
196
+
197
+ {
198
+
199
+ genre = textBox6.Text;
200
+
201
+ Sql(5, genre);
202
+
203
+ }
204
+
205
+
206
+
207
+ private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
208
+
209
+ {
210
+
211
+
212
+
213
+ }
214
+
215
+
216
+
217
+ private void button1_Click(object sender, EventArgs e)
218
+
219
+ {
220
+
221
+ //▼変数定義
222
+
223
+ string id = "";
224
+
225
+ string music = "";
226
+
227
+ string artist = "";
228
+
229
+ string album = "";
230
+
231
+ string date = "";
232
+
233
+ string genre = "";
234
+
235
+ DialogResult result;
236
+
237
+ DataTable dataT = new DataTable();
238
+
239
+ //テキストボックスのテキスト用配列
240
+
241
+ string[] search = new string[6];
242
+
243
+ //項目名用配列
244
+
245
+ string[] yourName = { "MusicID", "MusicName", "ArtistName", "AlbumName", "ReleaseDate", "Genre" };
246
+
247
+ //▲変数定義
248
+
249
+ //▼メソッド定義
250
+
251
+ //SQL文作成メソッド
252
+
253
+ void Sql(int index, string sq)
116
254
 
117
255
  {
118
256
 
119
- string sea = search[i];
257
+ search[index] = sq;
120
-
258
+
121
- //トラックナンバー用処理
259
+ //全体で使する基本のSQL、1=1はAND処理を楽にするため
260
+
122
-
261
+ string sql = "SELECT * FROM music WHERE 1 = 1";
262
+
263
+ //string sql = "SELECT * FROM music WHERE 1 = 1 AND CAST(TRACK_NO AS VARCHAR) LIKE '1%'";
264
+
123
- if (i == 0)
265
+ for (int i = 0; i < search.Length; i++)
124
266
 
125
267
  {
126
268
 
269
+ string sea = search[i];
270
+
271
+ //トラックナンバー用処理
272
+
273
+ if (i == 0)
274
+
275
+ {
276
+
127
- //前方一致処理
277
+ //前方一致処理
128
-
278
+
129
- sql += " AND " + "CAST(" + yourName[i] + " AS VARCHAR) LIKE '" + sea + "%'";
279
+ sql += " AND " + "CAST(" + yourName[i] + " AS VARCHAR) LIKE '" + sea + "%'";
280
+
281
+ }
282
+
283
+ //リリース用処理
284
+
285
+ else if (i == 4)
286
+
287
+ {
288
+
289
+ //後方一致処理
290
+
291
+ sql += " AND " + "CAST(" + yourName[i] + " AS VARCHAR) LIKE '%" + sea + "'";
292
+
293
+ }
294
+
295
+ else
296
+
297
+ {
298
+
299
+ //部分一致処理
300
+
301
+ sql += " AND " + yourName[i] + " LIKE '%" + sea + "%'";
302
+
303
+ }
130
304
 
131
305
  }
132
306
 
307
+ Debug.WriteLine("xxxxxxxxxxxxxxxxx");
308
+
309
+ Debug.WriteLine(sql);
310
+
311
+ Debug.WriteLine("xxxxxxxxxxxxxxxxx");
312
+
313
+ //データベース描画前に一度削除
314
+
315
+ dataGridView1.DataSource = "";
316
+
133
- //リリス用処理
317
+ //sql文エラに備えて
134
-
318
+
135
- else if (i == 4)
319
+ try
136
320
 
137
321
  {
138
322
 
139
- //後方一致処理
323
+ //SQL文実行処理
140
-
324
+
141
- sql += " AND " + "CAST(" + yourName[i] + " AS VARCHAR) LIKE '%" + sea + "'";
325
+ SqlConnection sqlconn = new SqlConnection(Properties.Settings.Default.sqlserver);
326
+
327
+ SqlCommand command = new SqlCommand(sql, sqlconn);
328
+
329
+ SqlDataAdapter adapter = new SqlDataAdapter(command);
330
+
331
+ DataTable dt = new DataTable();
332
+
333
+ adapter.Fill(dt);
334
+
335
+ //データベースをGridに渡して表示
336
+
337
+ dataGridView1.DataSource = dt;
338
+
339
+ dataT = dt;
340
+
341
+ //検索結果の件数を表示
342
+
343
+ int count = dt.Rows.Count;
344
+
345
+ label1.Text = count.ToString();
142
346
 
143
347
  }
144
348
 
145
- else
349
+ catch (Exception ex)
146
350
 
147
351
  {
148
352
 
149
- //部分一致処理
353
+ //エラー表示
150
-
354
+
151
- sql += " AND " + yourName[i] + " LIKE '%" + sea + "%'";
355
+ MessageBox.Show(ex.ToString());
152
356
 
153
357
  }
154
358
 
155
359
  }
156
360
 
157
- Debug.WriteLine("xxxxxxxxxxxxxxxxx");
158
-
159
- Debug.WriteLine(sql);
160
-
161
- Debug.WriteLine("xxxxxxxxxxxxxxxxx");
162
-
163
- //データベース描画前に一度削除
164
-
165
- dataGridView1.DataSource = "";
166
-
167
- //sql文エラーに備えて
168
-
169
- try
170
-
171
- {
172
-
173
- //SQL文実行処理
174
-
175
- SqlConnection sqlconn = new SqlConnection(Properties.Settings.Default.sqlserver);
176
-
177
- SqlCommand command = new SqlCommand(sql, sqlconn);
178
-
179
- SqlDataAdapter adapter = new SqlDataAdapter(command);
180
-
181
- DataTable dt = new DataTable();
182
-
183
- adapter.Fill(dt);
184
-
185
- //データベースをGridに渡して表示
186
-
187
- dataGridView1.DataSource = dt;
188
-
189
- dataT = dt;
190
-
191
- //検索結果件数表示
361
+ //ダイアログYesNo取得
192
-
362
+
193
- int count = dt.Rows.Count;
363
+ result = MessageBox.Show("一覧データを出力しますか?", "出力の確認", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
194
-
364
+
195
- label1.Text = count.ToString();
365
+ MessageBox.Show("一覧データを出力しました");
196
-
366
+
197
- }
367
+ }
198
-
199
- catch (Exception e)
200
-
201
- {
202
-
203
- //エラー表示
204
-
205
- //MessageBox.Show(e.ToString());
206
-
207
- }
208
-
209
- }
210
-
211
- //xmlダイアログのYes後処理
212
-
213
- //▲メソッド定義
214
368
 
215
369
 
216
370
 
217
- public Form1()
218
-
219
- {
220
-
221
- InitializeComponent();
222
-
223
- }
224
-
225
-
226
-
227
- private void Form1_Load(object sender, EventArgs e)
228
-
229
- {
230
-
231
- //maxとminを同じにすることでサイズ固定
232
-
233
- this.MaximumSize = this.Size;
234
-
235
- this.MinimumSize = this.Size;
236
-
237
- //最大化・最小化無効
238
-
239
- this.MaximizeBox = false;
240
-
241
- this.MinimizeBox = false;
242
-
243
- SqlConnection sqlconn = new SqlConnection(Properties.Settings.Default.sqlserver);
244
-
245
- sqlconn.Open();
246
-
247
- SqlCommand command = new SqlCommand("SELECT * from Musics", sqlconn);
248
-
249
- SqlDataAdapter adapter = new SqlDataAdapter(command);
250
-
251
- DataTable dt = new DataTable();
252
-
253
- adapter.Fill(dt);
254
-
255
- dataGridView1.DataSource = dt;
256
-
257
- dataT = dt;
258
-
259
- //検索結果の件数を表示
260
-
261
- int count = dt.Rows.Count;
262
-
263
- label1.Text = count.ToString();
264
-
265
- }
266
-
267
-
268
-
269
-
270
-
271
- private void textBox1_TextChanged(object sender, EventArgs e)
272
-
273
- {
274
-
275
- id = textBox1.Text;
276
-
277
- //値の種類とテキストボックスと項目名を渡す
278
-
279
- Sql(0, id);
280
-
281
- }
282
-
283
-
284
-
285
- private void textBox2_TextChanged(object sender, EventArgs e)
286
-
287
- {
288
-
289
- music = textBox2.Text;
290
-
291
- Sql(1, music);
292
-
293
- }
294
-
295
-
296
-
297
- private void textBox3_TextChanged(object sender, EventArgs e)
298
-
299
- {
300
-
301
- artist = textBox3.Text;
302
-
303
- Sql(2, artist);
304
-
305
- }
306
-
307
-
308
-
309
- private void textBox4_TextChanged(object sender, EventArgs e)
310
-
311
- {
312
-
313
- album = textBox4.Text;
314
-
315
- Sql(3, album);
316
-
317
-
318
-
319
- }
320
-
321
-
322
-
323
- private void textBox5_TextChanged(object sender, EventArgs e)
324
-
325
- {
326
-
327
- date = textBox5.Text;
328
-
329
- Sql(4, date);
330
-
331
-
332
-
333
- }
334
-
335
-
336
-
337
- private void textBox6_TextChanged(object sender, EventArgs e)
338
-
339
- {
340
-
341
- genre = textBox6.Text;
342
-
343
- Sql(5, genre);
344
-
345
- }
346
-
347
-
348
-
349
- private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
350
-
351
- {
352
-
353
-
354
-
355
- }
356
-
357
-
358
-
359
- private void button1_Click(object sender, EventArgs e)
360
-
361
- {
362
-
363
- //▼変数定義
364
-
365
- string id = "";
366
-
367
- string music = "";
368
-
369
- string artist = "";
370
-
371
- string album = "";
372
-
373
- string date = "";
374
-
375
- string genre = "";
376
-
377
- DialogResult result;
378
-
379
- DataTable dataT = new DataTable();
380
-
381
- //テキストボックスのテキスト用配列
382
-
383
- string[] search = new string[6];
384
-
385
- //項目名用配列
386
-
387
- string[] yourName = { "MusicID", "MusicName", "ArtistName", "AlbumName", "ReleaseDate", "Genre" };
388
-
389
- //▲変数定義
390
-
391
- //▼メソッド定義
392
-
393
- //SQL文作成メソッド
394
-
395
- void Sql(int index, string sq)
396
-
397
- {
398
-
399
- search[index] = sq;
400
-
401
- //全体で使用する基本のSQL、1=1はAND処理を楽にするため
402
-
403
- string sql = "SELECT * FROM music WHERE 1 = 1";
404
-
405
- //string sql = "SELECT * FROM music WHERE 1 = 1 AND CAST(TRACK_NO AS VARCHAR) LIKE '1%'";
406
-
407
- for (int i = 0; i < search.Length; i++)
408
-
409
- {
410
-
411
- string sea = search[i];
412
-
413
- //トラックナンバー用処理
414
-
415
- if (i == 0)
416
-
417
- {
418
-
419
- //前方一致処理
420
-
421
- sql += " AND " + "CAST(" + yourName[i] + " AS VARCHAR) LIKE '" + sea + "%'";
422
-
423
- }
424
-
425
- //リリース用処理
426
-
427
- else if (i == 4)
428
-
429
- {
430
-
431
- //後方一致処理
432
-
433
- sql += " AND " + "CAST(" + yourName[i] + " AS VARCHAR) LIKE '%" + sea + "'";
434
-
435
- }
436
-
437
- else
438
-
439
- {
440
-
441
- //部分一致処理
442
-
443
- sql += " AND " + yourName[i] + " LIKE '%" + sea + "%'";
444
-
445
- }
446
-
447
- }
448
-
449
- Debug.WriteLine("xxxxxxxxxxxxxxxxx");
450
-
451
- Debug.WriteLine(sql);
452
-
453
- Debug.WriteLine("xxxxxxxxxxxxxxxxx");
454
-
455
- //データベース描画前に一度削除
456
-
457
- dataGridView1.DataSource = "";
458
-
459
- //sql文エラーに備えて
460
-
461
- try
462
-
463
- {
464
-
465
- //SQL文実行処理
466
-
467
- SqlConnection sqlconn = new SqlConnection(Properties.Settings.Default.sqlserver);
468
-
469
- SqlCommand command = new SqlCommand(sql, sqlconn);
470
-
471
- SqlDataAdapter adapter = new SqlDataAdapter(command);
472
-
473
- DataTable dt = new DataTable();
474
-
475
- adapter.Fill(dt);
476
-
477
- //データベースをGridに渡して表示
478
-
479
- dataGridView1.DataSource = dt;
480
-
481
- dataT = dt;
482
-
483
- //検索結果の件数を表示
484
-
485
- int count = dt.Rows.Count;
486
-
487
- label1.Text = count.ToString();
488
-
489
- }
490
-
491
- catch (Exception ex)
492
-
493
- {
494
-
495
- //エラー表示
496
-
497
- MessageBox.Show(ex.ToString());
498
-
499
- }
500
-
501
- }
502
-
503
- //ダイアログのYesNoを取得
504
-
505
- result = MessageBox.Show("一覧データを出力しますか?", "出力の確認", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
506
-
507
- MessageBox.Show("一覧データを出力しました");
508
-
509
- }
510
-
511
-
512
-
513
371
 
514
372
 
515
373
  private void label1_Click(object sender, EventArgs e)