Garima Bansal

Garima Bansal

  • 1.1k
  • 683
  • 39.8k

How to solve violation of primary key cannot insert duplicate

Dec 6 2023 5:50 AM

I am trying to insert value from code in which i want talukcode = regioncode like 

model.talukcode = model.regioncode;

previously it was like

 model.villagecode = MaxValue + 1;

but now i am trying

model.talukcode = model.regioncode;

and i am getting an error 

System.Data.SqlClient.SqlException: Violation of PRIMARY KEY constraint 'PK_ppatalukmaster'. Cannot insert duplicate key in object 'dbo.ppatalukmaster'. The duplicate key value is (3, 3).
The statement has been terminated.

Is there any way to solve this error through code.


Answers (1)