C# 组合框和文本框之间的数据不一致
我试图让我的组合框中的数据在单击文本框后与它们相对应。但它不起作用。需要帮助,下面是我的代码C# 组合框和文本框之间的数据不一致,c#,database,windows,C#,Database,Windows,我试图让我的组合框中的数据在单击文本框后与它们相对应。但它不起作用。需要帮助,下面是我的代码 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { try { connection.Open(); OleDbCommand command = new OleDbCommand
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
string query = "select * from ExerciseData where FirstName='"+ comboBox1 .Text+"'";
command.CommandText = query;
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
EIDTB.Text = reader["EID"].ToString();
FirstNameTB.Text = reader["FirstName"].ToString();
LastNameTB.Text = reader["LastName"].ToString();
CountryTB.Text = reader["Country"].ToString();
}
connection.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error" + ex);
}
你试过了吗
comboBox1.SelectedItem.ToString()
而不是
comboBox1.Text
文本属性是,如果在组合框中键入文本,则所选项目是所选项目您遇到了什么错误?请阅读。