user3115280
user3115280

Reputation: 75

Update data with LinQ to SQL not working

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

Answers (2)

Try set the state of modification, before of "SubmitChanges"(SaveChanges):

db.Entry(stud).State = EntityState.Modified;

Upvotes: 1

Chris Ballard
Chris Ballard

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

Related Questions