Click here to Skip to main content
13,351,465 members (46,133 online)
Rate this:
 
Please Sign up or sign in to vote.
Dear sir,

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

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 12-Apr-12 3:06am
Updated 14-Nov-16 19:30pm
Comments
AshishChaudha 12-Apr-12 8:13am
   
provide the structure of both tables.when you are getting stucked?..
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
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...
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web02 | 2.8.180111.1 | Last Updated 15 Nov 2016
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100