日期:2014-05-18  浏览次数:21109 次

combox 绑定数据
我有个表studentinfo(studentid,studentname)
有个combox(学生编号,学生姓名)
现在要实现先择combox任意一项时查询.也就是可以按学生编号,或是学生姓名查询
select * from studentinfo where studenid=值这个语句是对
现在我想把查询条件改为combox下拉列表框里的任一项如何写select语句如何绑定combox里的内容


------解决方案--------------------
需要一个Combobox显示 学生编号,学生姓名 对应的Value为 studentid,studentname
还需要一个TextBox用于用户输入对应的条件值.
得到Sql语句
string cmdtext="select * from studentinfo where "+this.combobox1.SelectedValue+" ='" +textbox1.Text+ "'";
执行...
供你参考
------解决方案--------------------
先绑定ComboBox 
ComboBox .DisplayMember = "studentname";
ComboBox .ValueMember = "studentid";
ComboBox .DataSource = 要绑定的表;

然后获取ComboBox的值
select * from studentinfo where studenid=‘“+ComboBox.SelectedValue+"'

------解决方案--------------------
先绑定ComboBox 
ComboBox .DataSource = 要绑定的表; 
ComboBox .DisplayMember = "studentname"; 
ComboBox .ValueMember = "studentid"; 

获取ID:
int id=ComboBox.SelectedValue;