Click here to Skip to main content
15,909,953 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
protected void Page_Load(object sender, EventArgs e)
    {

       // Label1.Text = Request.QueryString["user"].ToString();
        Label1.Text = "welcome "+Request.QueryString["user"];
         TextBox4.Text = Request.QueryString["id"];//f_k


    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        conn.Open();
        cmd.Connection = conn;
        cmd.CommandText = "insert into book_info values('" + TextBox4.Text + "','" + TextBox1.Text + "','" + TextBox2.Text + "','" + TextBox3.Text + "')";
        cmd.ExecuteNonQuery();
        conn.Close();


        TextBox1.Text = "";
        TextBox2.Text = "";
        TextBox3.Text = "";
    }

}












{"The INSERT statement conflicted with the FOREIGN KEY constraint \"FK__book_info__f_use__0519C6AF\". The conflict occurred in database \"contact_book\", table \"dbo.logins\", column 'id'.\r\nThe statement has been terminated."}
Posted
Comments
[no name] 13-Jul-14 12:15pm    
http://stackoverflow.com/questions/2965837/insert-statement-conflicted-with-the-foreign-key-constraint

Seems like TextBox4 has the Foreign Key value. Either the value which you are trying is not present as a Primary Key in the referenced table or the value is not of the correct DataType as in database.
 
Share this answer
 
its a primary rule that before inserting any value in child table(having foreign key) corresponding value should always be present in Base/Parent Table(Primary key). It is possible that in your case in base table you don't have value for that primary key. So before inserting value in child table insert it in parent first.
 
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