您的位置:首页 > 其它

combobox下拉列表控件 关联绑定两个表的技巧

2009-11-13 10:27 344 查看
//绑定 SelectedValue 是关键

//要绑定一个工程单位(ppm,cm,m/s,...),下拉列表

string strTab = "cfg_eng_unit";
string strSql = "SELECT eng_unit_id,eng_unit FROM cfg_eng_unit;";

DataSet ds_Unit = MySql.GetDataFromTable(strTab, strSql, ref _conn);

//GetDataFromTable是我取数据库集的一个方法

comUnit.DataSource = ds_Unit.Tables[0].DefaultView;
comUnit.DisplayMember = "eng_unit";
comUnit.ValueMember = "eng_unit_id";

string strTab1 = "cfg_point_current";
string strSql1= "SELECT a.eng_unit_id,b.eng_unit,a.* FROM cfg_point_current a "+

" left join cfg_eng_unit b on a.eng_unit_id=b.eng_unit_id;";
DataSet ds1 = MySql.GetDataFromTable(strTab1, strSql1, ref _conn);

DataTable dt = ds1.Tables[0];

comUnit.DataBindings.Add("SelectedValue", dt, "eng_unit_id");//关键句
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐