Reputation: 359
I am using LINQ to SQL to interact with my database and I am trying to do the following to update a single row in the database:
DataClassesDataContext dataContext = new DataClassesDataContext();
TableName aRow = (from rows in dataContext.TableNames where rows.x == y select rows).Single();
aRow.attribute = "something";
dataContext.SubmitChanges();
shouldn't this update the database with the change I made to the row? or is there something I'm missing?
thanks for any help
Upvotes: 3
Views: 2805
Reputation: 28711
A couple of things to check:
DataContext
, meaning it's not cut and pasted from different methods where you're instantiating new DataContext
instances?DataContext.ObjectTrackingEnabled
property set to true
? It should be by default, but if it's false
then your DataContext
won't be able to perform the update. Upvotes: 1
Reputation: 793
That code should work correctly, so it must be elsewhere in the code or in the database itself.
Have you checked to make sure that the column you are updating is not read-only? As pst mentioned, are you using transactions?
Upvotes: 0