数据源错误:“无法绑定到属性或列"

编程入门 行业动态 更新时间:2024-10-22 14:01:31
本文介绍了数据源错误:“无法绑定到属性或列"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用 C# 处理数据库,当我点击显示按钮时出现错误:

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

错误:无法绑定到 DataSource 上的属性或列 LastName.参数名称:dataMember

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.

推荐答案

这意味着您的数据表没有找到数据库中的列名 LastName..

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];

应该是这样的..

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

因为您正在从绑定到ds"的 Program.tblNamesBS2 中寻找价值这就是为什么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"));

更多推荐

数据源错误:“无法绑定到属性或列"

本文发布于:2023-11-12 12:28:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1581500.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据源   绑定   属性   错误   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!