[分享]ComboBox绑定两个字段
很多时候我们在ComboBox中显示的并不是表中的ID,而在处理数据时我们需要的是ID,如果我们在ComboBox上绑定两个字段的话,那就很方便操作了
程序代码:private void Form1_Load(object sender, EventArgs e)
{
DataTable dt = GetData();
//绑定字段
= "UName";
= "UId";
= dt;
}
private DataTable GetData() //获取数据
{
using (OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Application.StartupPath + "\\db.mdb;Persist Security Info=False"))
{
OleDbDataAdapter adp = new OleDbDataAdapter("select * from temp", conn);
conn.Open();
DataTable dt = new DataTable();
adp.Fill(dt);
conn.Close();
return dt;
}
}示例:










这个我今天在做下拉框联动用到了哈
前几天我们老大教了我们了