I think it is the conflict between foreign key constraint.
This is the error . could you explain me why i getting this error?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sandeep Singh ShekhawatPosted Jul 18, 2013, 12:17 AM
Here tbl_Division is referenced table where row would be insert first and tbl_Student is child table where row would be insert after.
Allow null means it can have null values its not matter when it is not used as reference filed for foreign key. But it is using as reference field b/w these two table and DivisionId is primary key in
table tbl_Division so it can't not be null in table tbl_Division so it also can't be null in tbl_Student also because it is foreign key in table tbl_Student.We know that DesisionId will not be null in tbl_Division so its child table tbl_Student DivisionId field can't be null.
Suppose we insert a null value in child table tbl_Student DivisionId field that how can we map this value in refernced table tbl_Division?
Bineesh ViswanathPosted Jul 17, 2013, 11:28 PM
I have a table named tbl_Division and tbl_Student.
here the table where divisionId is PK;
I write code in the btnSave Click event in frmStudent is;
infostudent.divisionId=decimal.parse(cmbdivision.selectedindex.Tostring());
I checked in its Allow Null column in tbl_Student. here is the tbl_Student.
you can see the allow nulls column of divisionId is checked. Is this the problem?
which is referenced table and child table?
please explain
Kunal VaishyaPosted Jul 17, 2013, 8:06 AM
Sandeep Singh ShekhawatPosted Jul 17, 2013, 7:54 AM
You have two table that has foreign key relation on "divisionId" field. You should first insert value in your referenced table afterthat value will be insert in child table.
So first execute insert statement for referenced table thereafter you execute your insert query.
Thanks