Reputation: 75
My db table was Student, couldn't update after I press the update button. Data still the same.
string name = txtName.Text;
string dob = txtDOB.Text;
string tel = txtTelephone.Text;
string address = txtAddress.Text;
string email = User.Identity.Name;
Student stud = db.Students.Single(u => u.StudentEmail == email);
stud.Name = name;
stud.DateOfBirth = dob;
stud.Telephone = tel;
stud.Address = address;
db.SubmitChanges();
Response.Redirect("Home.aspx");
Upvotes: 0
Views: 116
Reputation: 160
Try set the state of modification, before of "SubmitChanges"(SaveChanges):
db.Entry(stud).State = EntityState.Modified;
Upvotes: 1
Reputation: 3769
Check whether the table has a Primary Key - if it doesn't, there is no way for LINQ to SQL to formulate the required UPDATE
statement.
Upvotes: 1