標籤:data img win str query word color splay https
一、如下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
C#winfor實現把資料庫的資訊顯示在comboBox上