DataSource error: quot;Cannot Bind to property or Columnquot;(数据源错误:“无法绑定到属性或列)
问题描述
我正在使用 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"));
这篇关于数据源错误:“无法绑定到属性或列"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:数据源错误:“无法绑定到属性或列"
基础教程推荐
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- 如果条件可以为空 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 获取C#保存对话框的文件路径 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- 将数据集转换为列表 2022-01-01
