简体   繁体   中英

Update button in datagrid, entity framework WPF Application

I'm attempting to create an update button, that you can press to automatically update a record within a DB.

the update button opens a new dialog, which then allows user to enter the updated details in text boxes and hit submit. This should then change the record within the DB and refresh the datagrid.

The code wont update the record within the DB.

[code removed for personal reasons]

While it would be better if you could refactor this in a proper MVVM style, your main problem is that your Student s2 is not attached to the context so there are no changes to be saved. Attach it to the context :

Student s2 = (Student)button.DataContext;
context.Students.Attach(s2);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM