无法绑定到新的显示成员。 [英] Cannot bind to the new display member.

查看:258
本文介绍了无法绑定到新的显示成员。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码&得到错误。

无法绑定到新的显示成员。

其中我有2个radiobutton& 1个组合框和1个按钮

i m using following code & get the error.
"Cannot bind to the new display member."
in which i m having 2 radiobutton & 1 combobox and 1 button

private void btnshow_Click(object sender, EventArgs e)
{
    panel1.Visible = false;
    if (rbparty.Checked == true)
    {
        panel1.Visible = true;
        fetchParty();
        //comboBox1.DisplayMember = "Table.P_Namee";
        //comboBox1.ValueMember = "P_Name";
        MessageBox.Show(rbparty.Text);
    }
    if (rbProduct.Checked == true)
    {
        panel1.Visible = true;
        fetchProduct();
        //comboBox1.DisplayMember = "Table.Prod_Name";
        //comboBox1.ValueMember = "Prod_Name";
        MessageBox.Show(rbProduct.Text);
    }
}




public void fetchProduct()
        {
            comboBox1.DisplayMember = "";
            da = new SqlDataAdapter("Select Prod_Name from tblProdMaster", con);
            DataSet ds = new DataSet();
            comboBox1.DataSource = ds;
            da.Fill(ds);
            comboBox1.DisplayMember = "Table.Prod_Name";
            comboBox1.ValueMember = "Prod_Name";


        }
        public void fetchParty()
        {
            comboBox1.DisplayMember = "";
            da = new SqlDataAdapter("Select P_Name from tblPartyMaster", con);
            DataSet ds1 = new DataSet();
            da.Fill(ds1);
            comboBox1.DataSource = ds1;
            comboBox1.DisplayMember = "Table.P_Namee";
            comboBox1.ValueMember = "P_Name";
        }



任何人都可以帮我。

感谢提前


can anyone help me pls.?
THANKS IN ADVANCE

推荐答案

只需删除 comboBox1.DisplayMember =; 并将Table.P_Namee替换为P_Name。



试试这个,

Just remove the comboBox1.DisplayMember = ""; and replace Table.P_Namee" with P_Name".

Try this,
public void fetchProduct()
        {
            da = new SqlDataAdapter("Select Prod_Name from tblProdMaster", con);
            DataSet ds = new DataSet();
            comboBox1.DataSource = ds;
            da.Fill(ds);
            comboBox1.DisplayMember = "Prod_Name";
            comboBox1.ValueMember = "Prod_Name";


        }
        public void fetchParty()
        {
            da = new SqlDataAdapter("Select P_Name from tblPartyMaster", con);
            DataSet ds1 = new DataSet();
            da.Fill(ds1);
            comboBox1.DataSource = ds1;
            comboBox1.DisplayMember = "P_Name";
            comboBox1.ValueMember = "P_Name";
        }


我知道这是一个旧帖子,但我遇到了这个问题,没有一个建议有用。事实证明,我遇到了问题的一个变种...



我在一个屏幕上有3个组合框,它们是级联的,必须有一些东西在第一个框中选择以激活和填充第二个框。类似地,第三个框仅在第二个框有选择时被激活并填充。



在我的屏幕初始加载时,当我尝试时,我一直收到错误在第一个框中设置值成员。关于第一个盒子的一切都很完美,其他盒子的数据元素设置也很合适。



事实证明,第一个盒子中的一个选择组合框没有任何数据显示在第二个组合框中。发生这种情况时,我的代码试图在DataSource中没有数据时为第二个组合框设置ValueMember。这就是导致无法绑定...错误的原因。几个小时的调试来找到这个,但修复是一个简单的if语句,在没有数据时没有为组合框设置ValueMember。
I know this is an old post, but I ran into this problem and none of the suggestions were helpful. As it turns out, I ran into a variation of the problem...

I have 3 combo boxes on one screen, and they are cascaded such that something must be selected in the first box in order to activate and populate the 2nd box. Similarly, the 3rd box is only activated and populated when the 2nd box has a selection.

On initial load of my screen, I kept getting an error thrown when I tried to set the value member in the first box. Everything about that first box was perfect, and the other boxes had their data elements set up properly as well.

As it turns out, one of the selections in the 1st combo box did not have any data to display in the 2nd combo box. When this happened, my code was trying to set the ValueMember for the 2nd combo box when there was no data in the DataSource. This is what caused the "could not bind..." error for me. Several hours of debugging to find this, but the fix was a simple "if" statement to not set the ValueMember for the combo box when there was no data.


我有同样的问题和寻找解决方案的很多网站,但我找到的解决方案非常简单。



虽然将数据绑定到COMBOBOX,但也添加了表格参考。以下是我的代码从存储的程序中加载COMBOBOX。



Dim cnBusBr作为新的SqlConnection(GetConnectionString(BuzzConnection))

Dim cmBusBr作为新的SqlCommand

Dim daBusBr作为新的SqlDataAdapter



使用cmBusBr

.Connection = cnBusBr
.CommandType = CommandType.StoredProcedure

.CommandText =spBusinessBranches

结束

HandleConnection(cnBusBr)



daBusBr.SelectCommand = cmBusBr

Dim dsBusBr作为新数据集

daBusBr.Fill(dsBusBr)

ctrl.DataSource = dsBusBr.Tables(0)

ctrl.DisplayMember =BBNAME

ctrl.ValueMember =BBID
I HAVE FACE SAME PROBLEM AND SEARCHED FOR THE SOLUTIONS ON MANY SITES, BUT THE SOLUTION I FOUND WAS VERY SIMPLE.

WHILE BINDING DATASOURCE TO COMBOBOX, ALSO ADD TABLE REFERENCE TO IT. BELOW IS MY CODE TO LOAD COMBOBOX FROM A STORED PROCEDURE.

Dim cnBusBr As New SqlConnection(GetConnectionString("BuzzConnection"))
Dim cmBusBr As New SqlCommand
Dim daBusBr As New SqlDataAdapter

With cmBusBr
.Connection = cnBusBr
.CommandType = CommandType.StoredProcedure
.CommandText = "spBusinessBranches"
End With
HandleConnection(cnBusBr)

daBusBr.SelectCommand = cmBusBr
Dim dsBusBr As New DataSet
daBusBr.Fill(dsBusBr)
ctrl.DataSource = dsBusBr.Tables(0)
ctrl.DisplayMember = "BBNAME"
ctrl.ValueMember = "BBID"


这篇关于无法绑定到新的显示成员。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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