数据源错误:"不能绑定属性或列" [英] DataSource error: "Cannot Bind to property or Column"

查看:204
本文介绍了数据源错误:"不能绑定属性或列"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的数据库在C#,当我打的显示按钮我得到一个错误:

I'm working on a database in C# when I hit the display button I get an error:

错误:结果
不能绑定到数据源的属性或列的名字。
参数名称:数据成员

Error:
Cannot bind to the property or column LastName on the DataSource. Parameter name: dataMember

代码:

private void Display_Click(object sender, EventArgs e)
{
    Program.da2.SelectCommand = new SqlCommand("Select * From Customer", Program.cs);
    Program.ds2.Clear();
    Program.da2.Fill(Program.ds2);
    customerDG.DataSource = Program.ds2.Tables[0];

    Program.tblNamesBS2.DataSource = Program.ds.Tables[0];

    customerfirstname.DataBindings.Add(new Binding("Text", Program.tblNamesBS2, "FirstName"));
    customerlastname.DataBindings.Add(new Binding("Text", Program.tblNamesBS2, "LastName")); //Line Error occurs on.
}



不知道这意味着什么谁能帮助,如果我注释掉最后两行会正确显示。

Not sure what it means can anyone help, if I comment out the last two lines it will display properly.

推荐答案

这意味着你的数据表中没有找到列名姓氏是在你的数据库..

it means your datatable is not finding column name LastName which is in your database..

在你的情况与DS2 ..

in your case you filling your dataset with ds2..

 Program.da2.Fill(Program.ds2); 



,然后你绑定您的数据源程序这样的..

and then you are binding your datasource to 'program' like this..

Program.tblNamesBS2.DataSource = Program.ds.Tables[0];  



应该喜欢这个..

it should like this..

Program.tblNamesBS2.DataSource = Program.ds2.Tables[0];  

由于以下行你正在寻找从Program.tblNamesBS2值被绑定到DS
和这就是为什么列不在DS疗法。

because below line you are looking value from Program.tblNamesBS2 which is binded to 'ds' and that's why column are not ther in 'ds'.

 customerfirstname.DataBindings.Add(new Binding("Text", Program.tblNamesBS2, "FirstName"));    
  customerlastname.DataBindings.Add(new Binding("Text", Program.tblNamesBS2, "LastName"));

这篇关于数据源错误:"不能绑定属性或列"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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