0

So I have a very simple Update method

  Public Sub SaveReferralFormSettings(ByVal p_clsReferralFormSettings As ReferralFormSetup)

        c_dbmlRefernet.Refresh(Linq.RefreshMode.OverwriteCurrentValues, p_clsReferralFormSettings)
        c_dbmlRefernet.SubmitChanges()

    End Sub

I have set primary key on the ReferralFormSettings table. I can see the object is fully populated.

but i still get error when trying to update the row in the db. Why??

I have tried removing the table from the dbml file then re-adding as suggested here How did I wrong my DataContext? also tried the replies in LINQ to SQL does not update when data has changed in database but I can not see why I am getting the error or how to resolve? any help greatly appreciated ty.

Also tried adding line

c_dbmlRefernet.ReferralFormSetups.Attach(p_clsReferralFormSettings)

still no joy

Fuzzybear
  • 1,378
  • 2
  • 23
  • 39

2 Answers2

1

In my case i got the error because i was trying to update a new table record, a record that was not yet created in the database.

MiguelSlv
  • 9,553
  • 7
  • 72
  • 127
0

Ok found my solution and what I was doing wrong. Hopefully this checklist will help others.

  1. Verify that Primary key set on your table and is in the dbml file
  2. Ensure that the object is populated when beiing passed into the method for the update.
  3. Now make sure you Attach the object to your dbml ie c_dbmlRefernet.ReferralFormSetups.Attach(p_clsReferralFormSettings)
  4. Ensure that you refresh with "KeepCurrentValues" to update the DB with the values passed in on the object.

Hope this helps.

Fuzzybear
  • 1,378
  • 2
  • 23
  • 39