需要C#组合框问题解决方案 [英] C# combobox problem solution required

查看:80
本文介绍了需要C#组合框问题解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个组合框,我从DB中填充它
这样,我在加载事件中称它为

Categorycls c = new Categorycls();
 comboBox1.DataSource = c.GetCategories();
  comboBox1.DisplayMember= "Category Description";
   comboBox1.ValueMember = "CatID";



和GetCategories为

public DataSet GetCategories()
        {
            d = new DBConnection();
            d.OpenConn();
            select = new OleDbCommand();
            select.CommandText = "Select * from [Categories]";
            select.Connection = d.getConnection();
            adapter = new OleDbDataAdapter(select);
            adapter.Fill(ds, "Categories");
            return ds;
        }


出现了问题,即在加载时显示并出现错误无法绑定到新的显示成员.
参数名称:newDisplayMember
列名与DB
相同 谁能说出原因和解决方法?
问候

解决方案

问题是您在数据集中获得了类别,而组合框仅在表中被接受.

试试这行

类别c =新的Categorycls();
 comboBox1.DataSource = c.GetCategories().Tables [ 0 ];
  comboBox1.DisplayMember = " ;
   comboBox1.ValueMember = " ; 


I have a combobox and i m populating it from DB
Like this,i called it in load event

Categorycls c = new Categorycls();
 comboBox1.DataSource = c.GetCategories();
  comboBox1.DisplayMember= "Category Description";
   comboBox1.ValueMember = "CatID";



and GetCategories is as

public DataSet GetCategories()
        {
            d = new DBConnection();
            d.OpenConn();
            select = new OleDbCommand();
            select.CommandText = "Select * from [Categories]";
            select.Connection = d.getConnection();
            adapter = new OleDbDataAdapter(select);
            adapter.Fill(ds, "Categories");
            return ds;
        }


the problem is arising that on load it displays and error "cannot bind to new display member.
Parameter name: newDisplayMember
The column names are same as of DB
Can any one tell the reason and solution?
Regards

解决方案

The Problem is your getting catefoiries in Dataset and the Combobox is accepted only in table.

Try this line

Categorycls c = new Categorycls();
 comboBox1.DataSource = c.GetCategories().Tables[0];
  comboBox1.DisplayMember= "Category Description";
   comboBox1.ValueMember = "CatID";


这篇关于需要C#组合框问题解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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