Error :
"The INSERT statement conflicted with the FOREIGN KEY constraint "FK_tb_stadmdet_tb_usr". The conflict occurred in database "admission", table "dbo.tb_usr", column 'usrcod'. The statement has been terminated."
Now if I will remove foreign key relationship, I am not getting the values from other tables to my table(because of which i have made foreign key relation).
Now what can be done to overcome this error, and I can get values from other tables to a table.
Thanks
Loading

Santhosh Kumar JayaramanPosted Jun 29, 2012, 9:10 AM
Santhosh Kumar JayaramanPosted Jun 29, 2012, 9:05 AM
protected void GridView1_SelectedIndexChanged1(object sender, EventArgs e)
{
string value1 = GridView1.SelectedRow.Cells[4].Text;
string value2 = GridView1.SelectedRow.Cells[5].Text;
//Label1.Text = value1;
//Label1.Text = Session["tm"].ToString();
Session["prgfee"] = GridView1.SelectedRow.Cells[6].Text;
//Label1.Text = Session["prgfee"].ToString();
if (Convert.ToInt32(value1) <= Convert.ToInt32(Session["tm"]))
{
obj.Save_Rec(objprp);
Response.Redirect("~/confirm.aspx");
}
You are not setting objprp to some value. Before that You are setting
nsadm.clsstadmdetprp objprp = new nsadm.clsstadmdetprp();
so all the columns in the objprp will be set to 0 if its int. In your case usercode is int, so it sets null.this save method tries to save with userid as 0, but there are no records for userid in tb_usr table for value 0. So throwing error "foreign key conflict"
Get the user details in session and set to objprp in admission.aspx page
Chakshu JindalPosted Jun 29, 2012, 8:46 AM
basically what i am doing here is,
student will register first(register.aspx), (table tb_usr gets the value when user registers), than after his successful registration, he will be redirected to the page(admission.aspx) where he can take admission in a particular programme,and when he opt to take admission, error occurs that i asked for.
Chakshu JindalPosted Jun 29, 2012, 8:21 AM
Santhosh Kumar JayaramanPosted Jun 29, 2012, 8:03 AM
Chakshu JindalPosted Jun 29, 2012, 7:18 AM
Santhosh Kumar JayaramanPosted Jun 29, 2012, 2:57 AM
Check whether the usercode exists in tb_Usr