I am using a TableAdapter
to connect to my database table.
When I perform an Update
and someone else has updated the same row I get a concurrency violation error. As expected.
So a开发者_如何学Pythont this point I give the user the option to Save regardless or Cancel changes
If they cancel I can just performs a Fill
to get an updated copy of the data but what if they want to overwrite? How do I actually force a save of the data overwriting the data held in the database?
If you are using a SQLCommandBuilder to generate your update statements then set CommandBuilder.ConflictOption=ConflictOption.OverwriteChanges; and then do the Update() again.
Right click table adapter, click 'Edit queries in Dataset designer'.
In the Data set designer window, select TableAdapter and go to its Properties.
In the properties, expand Update statement, and go into CommandText property. In the update command where condition, remove all the conditions and keep only the primary key column. for example:
UPDATE customer
SET column1 = @column1, column2 = @column2
WHERE pk_column = @pk_column
Now the concurrency exception wont appear again, since this query will overwrite the data based on the primary key alone.
精彩评论