Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Violation of PRIMARY KEY contraint Cannot insert duplicate key in object. when user exchanges primary keys

$
0
0

Hello,

When I call TableAdaptermanager.UpdateAll (in the save button event) I get a Violation of PRIMARY KEY contraint Cannot insert duplicate key in object.

This occurs if the users manipulated the primary key in a bound datagridview.

The user exchanges primary keys.

He does this:
ExampleTable

Index, Name, Enabled, Sortorder
1, Testname 1, True, 1
2, Testname 2, True, 2
3, Testname 3, True, 3

He first changes Index 2 to 4, then changed index 3 to 2 and then changes index 4 to 3 and then hit the save button.

If he presses the cancel button there should be nothing changed.

I already found a solution but can't use it. They say to remove all records and insert them again.

There are a lot of data and tables in my application that are depending on this primary key. They have cascaded update on them and should also be changed.

How to solve this issue?


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>