none
Update values gets reset to original values when updating database RRS feed

  • Question

  • I have a problem, when I try to update values from an application into a database. So far it's been working really great until I noticed that it failed to update a row in the database. After some testing and searching i found that the values I had updated reset themselves to the old values before i changed them. This ofcourse meant that LINQ didnt recognise any changes and therefore didnt update the database.
    Even more, I found that one value in this actually got updated, but even if this value always gets updated the remaining values gets reset before the update is done.

    the code i use looks like this:

    Work ind = db.Arbetes.Single(p => p.Work1 == wrkList[bef_val.SelectedIndex].Work1);

    ind.UE_Kod = komp_val.Text; //This value gets updated

    ind.Arbetsfrh_Kod = arbetsf_val.Text;

    ind.Probls_Kod = probl_val.Text;

    ind.Ansvar_Kod = ansv_val.Text;

    System.Data.Linq.ChangeSet ch = db.GetChangeSet();

    db.SubmitChanges();

    All values gets collected from ComboBoxes, and the ind.UE_KOD gets updated, but the rest of them gets set to the new value, but also gets reseted before the GetChangeSet() is called.
    I can update these values directly in the database, but not through LINQ.

    Any ideas as to why this is happening?

    Friday, March 27, 2009 8:32 AM

Answers

  • It seems like I fixed it. I had to re-create the DataContext everytime I do an update (tried it just now). So it works as it should now, but thank you for replying =)

    Monday, March 30, 2009 6:40 AM

All replies

  • If you really are setting those properties to different values I can't think of a good explanation for the behavior you're seeing. Is it possible for you to send this project to me at "david DOT dewinter AT rev-net DOT com" so I can verify what you're seeing?

    Sunday, March 29, 2009 4:30 PM
    Answerer
  • It seems like I fixed it. I had to re-create the DataContext everytime I do an update (tried it just now). So it works as it should now, but thank you for replying =)

    Monday, March 30, 2009 6:40 AM