当我运行后,先输入数字在textbox里点击确定后,会把符合条件的项赋到combobox里,当我把textbox里的数改了后在点击确定时,之前所留在combobox里的项还会存在,我的问题是要如何把之前所留在combobox里的项清空或者把重复的清除,在此谢谢各位大虾!!!
我的代码如下:
 private void button3_Click(object sender, EventArgs e)
        {
            int r = Convert.ToInt32(textBox1.Text);            if (textBox1.Text == "")
            {
                MessageBox.Show("请输入人数");
            }            else
            {
                textBox2.Enabled = true;
                textBox3.Enabled = true;
                comboBox1.Enabled = true;
                comboBox2.Enabled = true;
                dateTimePicker1.Enabled = true;
                SqlConnection con = new SqlConnection(@"server=.;database=CTGL;Integrated Security=sspi;");
                con.Open();
                SqlCommand com = new SqlCommand("select *  from [table]", con);
                DataSet ds = new DataSet();
                SqlDataAdapter adapter = new SqlDataAdapter("select  * from [table];select * from clerk", con);
                adapter.Fill(ds);                for (int cou = 0; cou <= ds.Tables[0].Rows.Count - 1; cou++)
                {
                    int b = Convert.ToInt32(ds.Tables[0].Rows[cou][2]);
                    string zt = ds.Tables[0].Rows[cou][5].ToString().Trim();
                    string zt2 = ds.Tables[0].Rows[cou][0].ToString().Trim();
                    if (zt == "空闲" && r <= b)
                    {
                        comboBox1.Items.Add(zt2);
                    }
                    for (int count = 0; count <= ds.Tables[1].Rows.Count - 1; count++)
                    {
                        comboBox2.Items.Add(ds.Tables[1].Rows[count][1].ToString());                    }
                }
                con.Close();            }