3
在數據庫中沒有發現錯誤和newUser對象,但數據庫未被修改。有什麼問題。作爲新的學習者,非常感謝精心製作的答案。謝謝。實體更新不起作用,更新過程中沒有錯誤。
TBL_LogIn newUser = new TBL_LogIn();
newUser = hrmsDb.TBL_LogIn.Where(x => x.EmployeeID == inputEmployeeID).FirstOrDefault();
try
{
if (newUser != null)
{
AddLogInInfo(newUser);
hrmsDb.Entry(newUser).State = EntityState.Modified;
hrmsDb.SaveChanges();
}
else
{ }
}
catch (Exception ex)
{
throw;
}
/*-----Functions to Update New Employee Information in Three tables-------*/
private void AddLogInInfo(TBL_LogIn newUser)
{
string UserName = TextBoxUsername.Text;
string Password = TextBoxPassword.Text;
string UserType = TextBoxUserType.Text;
newUser.UserName = UserName;
newUser.PassWord = Password;
newUser.UserType = UserType;
}
你的代碼是否到達**如果語句**?換句話說,確保'newUser!= null'爲真。 – Win
'AddLogInInfo'更新現有記錄? –
是的我的代碼到達** if語句**內部,然後進入** AddLogInInfo()**函數。我確信'newUser!= null'是真的。 @Win。 ** AddLogInInfo **更新現有記錄@Mathew – Leon