devtunis devtunis - 1 year ago 123
C# Question

Update with Entity Framework C#

I want to update items by Entity Framework,

The code is correct but i don't have result in my database!!

using(checkinentrepriseEntities2 context = new checkinentrepriseEntities2()) {
clients clien = new clients();

clien.date_arrival = DateTime.Parse(textBoxDateIN.Text);
clien.arrival_time = textBoxTIME.Text;
clien.Aller_A = comboboxPersonnel.SelectedItem.ToString();
clien.Badge = int.Parse(comboBoxBadge.SelectedItem.ToString());

int badgeTiped = int.Parse(comboBoxBadge.SelectedItem.ToString());


Answer Source

This code is creating a new clients object.

If you want to update results from the database you have to select the clients object from the database :

clients clien = context.clients.Single(x => x.Id == yourId);
// your logic
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download