none
ado RRS feed

  • Question

  • hi everybody

    pleease help me

    when i write the code below it shows an error that

    The INSERT statement conflicted with the FOREIGN KEY constraint "FK_questions_quiz". The conflict occurred in database "C:\DOCUMENTS AND SETTINGS\AQEEL\DESKTOP\DEMONEW\APP_DATA\DATABASE.MDF", table "dbo.Quiz", column 'Quiz_ID'.
    The statement has been terminated.


    con.Open();
    SqlCommand cmd = new SqlCommand("insert into Questions(Quiz_Id,Q_Desc)values('" + Quiz_Id + "','" + QuestionTxBx.Text + "')", con);
    cmd.ExecuteNonQuery();
    con.Close();
    errorLabl.Text = "question Succesfully Saved";
    QuestionTxBx.Enabled = false;
    en();
    Button2.Enabled = false;
    SqlCommand cmd1 = new SqlCommand("select top 100 Q_No *from Questions order by Q_No Desc", con);
    con.Open();
    r=cmd.ExecuteReader();
    if (r.Read())
    {
    Q_Id = r["Q_No"].ToString();
    Session["QQ_Id"] = Q_Id;
    Q_No++;
    r.Close();
    con.Close();


    Monday, March 21, 2011 5:27 AM

Answers

  • Hello aqeeel,

     

    Welcome to the ADO.NET DataSet Forum!

    According to your description, I think the error is because you didn't insert the related records in the related table. So if you're using the Visual Studio to insert a record, make sure you have already added the related records to the parent tables. Please check the statement.

    I hope this can help you.

     

    Have a nice day,


    Jackie Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, March 22, 2011 1:53 AM
    Moderator

All replies

  • hi everybody

    pleease help me

    when i write the code below it shows an error that

    The INSERT statement conflicted with the FOREIGN KEY constraint "FK_questions_quiz". The conflict occurred in database "C:\DOCUMENTS AND SETTINGS\AQEEL\DESKTOP\DEMONEW\APP_DATA\DATABASE.MDF", table "dbo.Quiz", column 'Quiz_ID'.
    The statement has been terminated.


    con.Open();
    SqlCommand cmd = new SqlCommand("insert into Questions(Quiz_Id,Q_Desc)values('" + Quiz_Id + "','" + QuestionTxBx.Text + "')", con);
    cmd.ExecuteNonQuery();
    con.Close();
    errorLabl.Text = "question Succesfully Saved";
    QuestionTxBx.Enabled = false;
    en();
    Button2.Enabled = false;
    SqlCommand cmd1 = new SqlCommand("select top 100 Q_No *from Questions order by Q_No Desc", con);
    con.Open();
    r=cmd.ExecuteReader();
    if (r.Read())
    {
    Q_Id = r["Q_No"].ToString();
    Session["QQ_Id"] = Q_Id;
    Q_No++;
    r.Close();
    con.Close();


     

     

    c#

    Monday, March 21, 2011 5:38 AM
  • Hello aqeeel,

     

    Welcome to the ADO.NET DataSet Forum!

    According to your description, I think the error is because you didn't insert the related records in the related table. So if you're using the Visual Studio to insert a record, make sure you have already added the related records to the parent tables. Please check the statement.

    I hope this can help you.

     

    Have a nice day,


    Jackie Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, March 22, 2011 1:53 AM
    Moderator