Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
[SqlException (0x80131904): Violation of PRIMARY KEY constraint 'PK_Teacher'. Cannot insert duplicate key in object 'dbo.Teacher'.
The statement has been terminated.]
DBAccess.DB.ExecuteSQL(String Sql) in C:\NIOS_DElEd_Bridge\DBAccess\DB.cs:106
NIOS.DElEd.Teacher.RegForm.Submit_Clicked(Object sender, EventArgs e) in C:\NIOS_DElEd_Bridge\NIOS_DElEd_Bridge\Teacher\RegForm.aspx.cs:601
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +155
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3804

What I have tried:

I have tried nothing yet. Emergency here.
Posted
Updated 20-Jul-23 6:00am
Comments
A_Griffin 17-Oct-17 14:11pm    
The error is pretty clear. You are trying to insert a record with primary key value that already exists in the database.

As mentioned in the comments, the error is telling you exactly what the problem is. You are trying to insert a value into Teacher table primary key field that already exists.
 
Share this answer
 
As the error says, you're trying to insert a record to the table with a key value already existing in the table.

The first thing to do is to have a look at the primary key definition. Open up SSMS and navigate to your table in your database. Expand the keys node and you should see the PK_Teacher. Right click it and select modify. This brings you to design window where you see the definition for your key.

Now check if the key is what you expect it to be. If it's a natural key, for example name, then you need to provide other information when inserting the data or alter the key to contain desired columns. If the key is an identity column it shouldn't cause duplicates unless someone has reseeded the counter. In such case reseeding the counter to last existing value should fix the problem.

But to be honest, it would help a lot to see the table definition so if you need more detailed information, please update the question to contain the script for the table.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900