c# - 无法更新List1 : it has no PK

标签 c# sqlite visual-studio-2012 sqlite-net

我正在尝试更新数据库中的记录,更改是在我为页面创建的列表上进行的,但是当我尝试更新数据库本身时,我收到一条错误消息

Cannot update List1: it has no PK

应用程序在最后一行代码处中断。我的表有一个主键。它应该是 Students 中的 Tno

private void ChangeMajor_Button_Click(object sender, RoutedEventArgs e)
{
    var query = Roster_Students.Where(s => s.Tno == Tno_TextBox.Text);
    foreach (var student in query)
        student.Major = ChangeMajor_TextBox.Text;

    App.DBConnection.Update(this.Roster_Students);        
}

最佳答案

稍微修改一下代码似乎可以解决问题。这是新代码:

private void ChangeMajor_Button_Click(object sender, RoutedEventArgs e)
{
    var query = Roster_Students.Where(s => s.Tno == Tno_TextBox.Text);
    foreach (var student in query) {
        student.Major = ChangeMajor_TextBox.Text;
        App.DBConnection.Update(student);
    }
}

关于c# - 无法更新List1 : it has no PK,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20362266/

相关文章:

c# - 我的 lambda 表达式没有产生我预期的结果

c# - 将 XML 反序列化为对象 C#

ios - Core Data 与 SQLite 用于通过 OData 公开的现有数据库的离线持久性

iphone - 如何保持 SQLite 数据库和 UITableView 同步

reporting-services - 部署报表时是否可以转换连接字符串? (针对 VS 2012/SSRS 的 SSDT 出价)

performance - Visual Studio 2012 编译速度慢,互联网使用率高

c# - ASP MVC 应用程序在长时间运行的线程上重置

c# - 扩展类成员的扩展方法?

c++ - 为什么我不能在 SQLite 中的 VIEW 上创建触发器?

c++ - 错误 C4996 : 'std::_Copy_impl' : Function call with parameters that may be unsafe