c# comboBox要取不重复选项!
怎么再加多"用车"在comboBox2, "部门"在comboBox3,要取不重复的! 我试过stri...
怎么再加多"用车"在comboBox2, "部门"在comboBox3,要取不重复的! 我试过string sql = "select distinct 编号,用车,部门 from UW"; //或者用* comboBox1.Items.Clear();comboBox2.Items.Clear();comboBox3.Items.Clear();while(reader.Read()){ comboBox1.Items.Add((string)reader["编号"]); comboBox2.Items.Add((string)reader["用车"]); comboBox3.Items.Add((string)reader["部门"]); 上面那样会重复,下面单个就不会重复.请问我要怎么改才不会复啊, 谢谢各位的帮忙! private void Form3_Load(object sender, EventArgs e) { string strconnection = "provider=microsoft.jet.oledb.4.0;Data Source=" + Application.StartupPath + @"\MBD\UW.mdb"; OleDbConnection cusconnection = new OleDbConnection(strconnection); cusconnection.Open(); string sql = "select distinct 编号 from UW"; OleDbCommand cmd = new OleDbCommand(sql, cusconnection); OleDbDataReader reader = cmd.ExecuteReader(); comboBox1.Items.Clear(); while(reader.Read()){ comboBox1.Items.Add((string)reader["编号"]); } cmd.Dispose(); reader.Close(); cusconnection.Close();
展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询