質問するログイン新規登録

質問編集履歴

1

説明不足

2018/12/03 06:00

投稿

maam
maam

スコア55

title CHANGED
File without changes
body CHANGED
@@ -4,4 +4,40 @@
4
4
  var adapter = new SqlDataAdapter(command);
5
5
  adapter.Fill(table);
6
6
 
7
- いろいろ調べてみるとこういった形が多いのですが、これでは全ての検索結果を表示できませんでした。なにかアドバイスをいただけないでしょうか。
7
+ いろいろ調べてみるとこういった形が多いのですが、これでは全ての検索結果を表示できませんでした。なにかアドバイスをいただけないでしょうか。
8
+
9
+ ```
10
+
11
+ private void KensakuBt_Click(object sender, EventArgs e)
12
+ {
13
+ // 接続文字列の取得
14
+ var connectionString = ConfigurationManager.ConnectionStrings["sqlsvr"].ConnectionString;
15
+
16
+ // データベース接続の準備
17
+ using (var connection = new SqlConnection(connectionString))
18
+ using (var command = connection.CreateCommand())
19
+ {
20
+
21
+ String sei = textBox1.Text;
22
+ String mei = textBox2.Text;
23
+ String man = radioButton1.Text;
24
+ String woman = radioButton2.Text;
25
+ String yuubin = textBox3.Text;
26
+ try
27
+ {
28
+ //データベースの接続開始
29
+ connection.Open();
30
+
31
+ // SQLの条件設定
32
+ command.CommandText =
33
+ @"SELECT TOP 10 count * FROM MEMBER_MASTER"   //上位10件の表示
34
+ + "WHERE MEMBER_MASTER.name1 LIKE '%" + sei + "%'"  //姓との部分一致
35
+ + "WHERE MEMBER_MASTER.name2 LIKE '%" + mei + "%'"  //名との部分一致
36
+ + "WHERE MEMBER_MASTER.gender = " + man
37
+ + "WHERE MEMBER_MASTER.gender = " + woman
38
+ + "WHERE MEMBER_MASTER.adress = " + yuubin
39
+ + "ORDER BY MEMBER_MASTER.id"; //IDの昇順に表示
40
+
41
+ ```
42
+
43
+ この後にどう表示すればよいでしょうか