0

I am having an issue with linq2sql data connector not updating the data object when I call Submit Changes

I have this code on a button click event, Though it is failing because it is setting Index to 1( which exists in the db) – not 3 as I have assigned in the object

I started getting a DuplicateKetException was unhandled, and if I view the details I see the object has old data in it ( Index = 1,Model = blah,Service = blah)

What am I doing wrong, is there some cache I need to flush???

public void button_Add_Click(object sender, RoutedEventArgs e)
{
    using (DataClasses1DataContext dc = new  DataClasses1DataContext());
    {
        Equipment equip = new Equipment
        {
            Index = 3,
            Model = “ABCD1234",
            Service = DateTime.Now
        };
        //Add the new object to the equip collection.
        dc.Equipments.InsertOnSubmit(equip);
        //Submit the change to the database.
        dc.SubmitChanges();
    }
    //catch (Exception e)
    {
        //Console.WriteLine(e);
        dc.SubmitChanges();
    }
}
Keyur PATEL
  • 2,299
  • 1
  • 15
  • 41
Faust
  • 97
  • 1
  • 1
  • 4
  • Assuming you comment out the second `dc.SubmitChanges();`, and the brackets. – Keyur PATEL Sep 22 '16 at 01:31
  • 1
    Also, is `index` your primary key, or auto increment? If so, you don't need to set a value from code. – Keyur PATEL Sep 22 '16 at 01:33
  • Index is the primary key? Can I make it auto increment? – Faust Sep 22 '16 at 08:58
  • Regardless, none of the other item in the object are updated. I dont undersatnd why – Faust Sep 22 '16 at 11:57
  • I have found my issue, when I run my application by clicking Start on the tool bar, It is not running my current code. I tried to publish and it errored the SignTool.exe was not found - but it did produce a exe that works as it should..... – Faust Sep 22 '16 at 12:48
  • Try following these steps: http://stackoverflow.com/a/33666943/6741868 – Keyur PATEL Sep 23 '16 at 01:21

0 Answers0