I'm trying to update a record in a database, the changes are made on the list that I create for the page, but when I try to update the database itself, I get an error that states
Cannot update List1: it has no PK
The application breaks on the last line of code. My table has a primary key. It should be Tno
in 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(this.Roster_Students);
}
Modifying the code a little seemed to resolve the issue. Here is the new code: