我需要帮助将listbox
输出中的数据显示到标签。
在listbox
中,所有内容都已加载(我需要查看Firstname
和LastName
),但它不会在标签上写任何内容 - 始终是错误。
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
string query = "SELECT * FROM Tab1 WHERE groupA='" + listBox1.Text + "' ORDER BY FirstName";
command.CommandText = query;
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
listBox3.Items.Add(reader["FirstName"].ToString() + " " + reader["LastName"].ToString());
}
connection.Close();
}
catch (Exception ex)
{
MessageBox.Show("ERROR" + ex);
}
}
listBox3_SelectedINdexChanged
private void listBox3_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
string query = "select * from Tab1 where FirstName=" + listBox2.Text + "";
command.CommandText = query;
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
label6.Text = reader["FirstName"].ToString();
label8.Text = reader["LastName"].ToString();
label10.Text = reader["GroupPolice"].ToString();
}
connection.Close();
}
catch (Exception ex)
{
MessageBox.Show("ERROR" + ex);
}
}
答案 0 :(得分:0)
将第二个查询更改为:
string query = "select * from [Tab1] where FirstName='" + listBox2.Text + "'";
while (reader.Read())
来:
if (reader.Read())