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

質問編集履歴

1

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

2020/03/31 14:30

投稿

pj7577bm60v
pj7577bm60v

スコア13

title CHANGED
File without changes
body CHANGED
@@ -45,6 +45,97 @@
45
45
  rd.Close();
46
46
  cn.Close();
47
47
  }
48
+
49
+ //追記させていただきました。
50
+ using System;
51
+ using System.Collections.Generic;
52
+ using System.ComponentModel;
53
+ using System.Data;
54
+ using System.Drawing;
55
+ using System.Linq;
56
+ using System.Text;
57
+ using System.Threading.Tasks;
58
+ using System.Windows.Forms;
59
+ using System.Data.SqlClient;
60
+
61
+ namespace WindowsFormsApp4
62
+ {
63
+ public partial class Form1 : Form
64
+ {
65
+ private SqlConnection cn = new SqlConnection();
66
+ private SqlCommand cmd = new SqlCommand();
67
+ private SqlDataReader rd;
68
+ private String cnstr = @"Data Source=(LocalDB)\MSSQLLocalDB;" + @"AttachDbFilename=|DataDirectory|\Schedule2.mdf;" + "Integrated Security = True; Connect Timeout = 30";
69
+ private string name = "";
70
+ private DateTime date = new DateTime(2000, 1, 1);
71
+ private string task = "";
72
+
73
+ readonly List<ListBox> listBoxs;
74
+
75
+ public Form1()
76
+ {
77
+ InitializeComponent();
78
+
79
+ listBoxs = new List<ListBox>
80
+ {
81
+ null,
82
+ listBox1,
83
+ listBox2,
84
+ listBox3,
85
+ listBox4,
86
+ listBox5,
87
+ listBox6,
88
+ listBox7,
89
+ listBox8,
90
+ listBox9,
91
+ listBox10,
92
+ listBox11,
93
+ listBox12,
94
+ listBox13,
95
+ listBox14
96
+ };
97
+ }
98
+
99
+ private void button1_Click(object sender, EventArgs e)
100
+ {
101
+
102
+ cn.ConnectionString = cnstr;
103
+ cn.Open();
104
+
105
+ cmd.Connection = cn;
106
+ cmd.CommandType = CommandType.Text;
107
+ cmd.CommandText = "SELECT * FROM [dbo] . [Table]";
108
+
109
+ rd = cmd.ExecuteReader();
110
+ while (rd.Read())
111
+ {
112
+ name = Convert.ToString(rd["名前"]);
113
+ date = Convert.ToDateTime(rd["日付"]);
114
+ task = Convert.ToString(rd["タスクネーム"]);
115
+
116
+ if (name == "A")
117
+ {
118
+ var listBox = listBoxs[ListBoxItems];
119
+ //listBox.Items.Add = task;
120
+ }
121
+
122
+ }
123
+ rd.Close();
124
+ cn.Close();
125
+ }
126
+
127
+ private int ListBoxItems
128
+ {
129
+
130
+ get
131
+ {
132
+ //if (date ==3,1 ) return 1;
133
+
134
+ return 0;
135
+ }
136
+ }
137
+ }
138
+ }
48
139
  ```
49
140
 
50
141
  ### 試したこと