通过C#中的数据源连接时从组合框获取值 [英] Getting values from combo box when connected by data source in c#

查看:85
本文介绍了通过C#中的数据源连接时从组合框获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我是新来的.还有一个大问题,如果您能提供帮助,我将不胜感激.

我正在开发一款仅将一些数据输入访问文件并经过一些过滤(通过使用日期时间选择器,单选按钮,组合框等完成)进行检索的软件.

当我想更新任何条目时,我只需编写一个选择查询并将这些值添加到相关字段中.但问题是我无法更新组合框.我有两个.当我尝试遵循以下代码时,它将引发错误.

我能做些什么?请帮帮我.谢谢!

Hi,
Im new here. And have a big issue which I will really appreciate if you could help with.

Im developing a software which is just entering some data to the access file and retrieve it after some filtering (done by using date time pickers, radio buttons, combo boxes...etc)

When I want to update any entry I simply write a select query and add those values to relevant fields. But thing is that I cannot update my combo boxes. I got 2 of them. When I try following code it throws errors.

What can I do? pls help me out. Thanks!

cmb_district.ValueMember = dt1.Rows[0][1].ToString();



我使用数据源属性将组合框与Access数据库连接.显然,它具有显示和有价值的成员.但是当查询返回值时,它不会更新组合框并给出以下错误.

无法绑定到新的value成员.
参数名称:值

谢谢.请帮我!



I use the data source property to connect combo box with access database. It clearly has display and value members. But When query returns the value it do not update the combo box and give following error.

Cannot bind to the new value member.
Parameter name: value

Thanks. Pls help me out!

推荐答案



使用数据集分配组合框的数据源属性.

Hi,

Use DataSet to assign the Datasource property of combobox.

ComboBox1.DataSource = MyDataTable.DefaultView;
ComboBox1.DisplayMember = "DisplayFieldName";
ComboBox1.ValueMember = "ValueFieldName";


comboBox1.Name = "comboBox1";
comboBox1.DataSource = "select ur databinding source";
comboBox1.DisplayMember = "field name";            
comboBox1.ValueMember = "field name";




最后,您输入了表单加载事件,调用了绑定源




finally u have enter the form load events call the binding source


这篇关于通过C#中的数据源连接时从组合框获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆