Click here to Skip to main content
15,898,937 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I have class that has a foreign key, where i define an object from it and insert in db i don't assign foreign key because it must assign in another page and i assign foreign key to null but I get this error:

Cannot insert the value NULL into column 'GdtStdUN', table 'HomeWorkSystem.dbo.Course'; column does not allow nulls. INSERT fails. The statement has been terminated.

thank you
Posted
Updated 28-May-12 22:54pm
v2

1 solution

where i define an object from it and insert in db i don't assign foreign key because it must assign in another page and i assign foreign key to null but I get this error
Defining a Foreign Key puts a foreign key constraint on that column. Looks like this constraint has been defined as having NOT NULL value right now, hence the error. You have to define it as NULL allowed to reference it later.

Details here: MSDN: FOREIGN KEY Constraints[^]
MSDN: Creating and Modifying FOREIGN KEY Constraints[^]
 
Share this answer
 
Comments
parisa heidari 31-May-12 11:30am    
thanks it was very useful.
Sandeep Mewara 31-May-12 12:19pm    
Welcome.

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