一、如下comboBox1、comboBox2、comboBox3,原来这三个都是空的,
将数据库中的省份传递到comboBox1中
二、在Load方法中,
1、用sql命令查询要在comboBox中显示的值
2、将值给DataTable
3、DisplayMember 就是要显示的数据库中的字段:org_short_name
private void test_Load(object sender, EventArgs e) { using (SQLiteConnection con = new SQLiteConnection(Constants.DATA_SOURCE)) { con.Open(); using (SQLiteCommand cmd = new SQLiteCommand()) { cmd.Connection = con; cmd.CommandText = string.Format("select t.org_short_name from sys_orgtable t "); int rows = cmd.ExecuteNonQuery(); SQLiteDataAdapter sda = new SQLiteDataAdapter(cmd); DataTable dt = new DataTable(); sda.Fill(dt); comboBox1.DataSource = dt; comboBox1.DisplayMember = "org_short_name"; } } }
三、结果
参考:
https://zhidao.baidu.com/question/242563101.html?qbl=relate_question_2&word=c%20combobox%BC%D3%D4%D8%CA%FD%BE%DD&skiptype=2
时间: 2024-10-12 12:01:06