做combobox绑定时,该怎么处理
做combobox绑定时
combobox1绑定SQL数据库表系别表,根据系别名称,来找出对应班级表中的班级,并绑定在combobox2。
系别表:系别号,系别名称;
班级表:班级号,系别号,班级名;
求代码?
------解决方案--------------------
第一个绑定的是 系别号, 第二个则绑定的是 班级号
string xibiehao=combobox1.text;
select * from 班级表 where 系别号='xibiehao'
在 combox1中绑定变行了,你试试。
------解决方案--------------------
combobox1绑定SQL数据库表系别表,根据系别名称,来找出对应班级表中的班级,并绑定在combobox2。
系别表:系别号,系别名称;
班级表:班级号,系别号,班级名;
求代码?
------解决方案--------------------
第一个绑定的是 系别号, 第二个则绑定的是 班级号
string xibiehao=combobox1.text;
select * from 班级表 where 系别号='xibiehao'
在 combox1中绑定变行了,你试试。
------解决方案--------------------
- C# code
string sql="Select * from 系别表"; DataTable Deptdt = DBHelper.GetTable(sql); combobox1.DataSource = Deptdt; combobox1.DisplayMember = "系别号"; combobox1.ValueMember = "系别名称"; private void cboDept_SelectedIndexChanged(object sender, EventArgs e) { string sql="select * from 班级表 a,系别表 b where a.系别号=b.系别号 and a.系别号 =combobox1.selectedValue"; DataTable ClassDt= DBHelper.GetTable(sql); combobox2.DataSource = ClassDt; combobox2.DisplayMember = "班级号"; combobox2.ValueMember = "班级名"; }
------解决方案--------------------
5楼的DBHelper是另为定义的类,你把他看作得到了这张系表表