Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear sir,

I have some problem when inserted data in the database.The error should be described as follows :-

SQL
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_Student_Resource". The conflict occurred in database "SusanneDB", table "dbo.Resource", column 'ResourceId'.
The statement has been terminated.



please suggest to me or guidelines about my error.

thanks in advanced...
Posted
Updated 14-Nov-16 18:30pm
Comments
AshishChaudha 12-Apr-12 8:13am    
provide the structure of both tables.when you are getting stucked?..

From that little, we can't give you any exact code help: but the error is pretty explicit.

ResourceId is in a foreign key relationship with another table, which does not contain the ID you are trying to insert. Insert the value in the Resource table first, or check and correct the value you are inserting in resourceID
 
Share this answer
 
Comments
Member 9351718 1-Jan-13 2:16am    
I also have the same error. I have CasteMaster table in that few records are present. In studentMaster table I have foreign key with CasteMaster table. But getting the same error
OriginalGriff 1-Jan-13 3:05am    
So the same comment stands.
Fix it the same way...
Hi Dear,

Root cause of this issue is that while inserting data into table having foreign key with 0/null value of primary key column value. In your case resource Id is having either 0 or null and it is being inserted into table having foreign key.

Solution: 1) You have to apply multiple checks/validations according to your need and pop up a valid error message on UI.
2) Trace why you are not getting primary key value. Problem can be in bindings if MVC or WPF used.
 
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