Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 组合框和文本框之间的数据不一致_C#_Database_Windows - Fatal编程技术网

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

文本属性是,如果在组合框中键入文本,则所选项目是所选项目

您遇到了什么错误?请阅读。