Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)

Here's the table

Users

UserId

UserName

Password

EmailAddress

and code...

public void ChangePassword(int userId, string password){

//code to update the password...

}

1 Answer

0 votes
by (40.7k points)

Try the below code:

public void ChangePassword(int userId, string password)

{

  var user = new User() { Id = userId, Password = password };

  using (var db = new MyEfContextName())

  {

    db.Users.Attach(user);

    db.Entry(user).Property(x => x.Password).IsModified = true;

    db.SaveChanges();

  }

}

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...