studentBindingSource.Add(new Student()); error SQL



当我尝试使用以下代码将新用户添加到我的数据库时出错:

private void btnAdd_Click(object sender, EventArgs e)
{
objState = EntityState.Added;
pic.Image = null;
pContainer.Enabled = true;
studentBindingSource.Add(new Student());
studentBindingSource.MoveLast();
txtFullName.Focus();
}

它看到我一个错误错误System.InvalidOperationException:"添加到BindingSource列表中的对象必须属于同一类型。

请帮忙

集合(如 List(一次只能包含一种数据类型。

例如,字符串数组只能包含字符串。向其添加整数会给您带来问题

我没有足够的代码来确切地告诉您发生了什么,但似乎您的studentBindingSource集合并不意味着包含学生。它包含另一种数据类型

最新更新