我的数据库表是学生,按下更新按钮后无法更新。数据还是一样的
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");
尝试设置"SubmitChanges"(SaveChanges)之前的修改状态:
db.Entry(stud).State = EntityState.Modified;
检查表是否有Primary Key,如果没有,LINQ to SQL将无法制定所需的UPDATE
语句