protected void btnSave_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["BD_TrainingConnectionString"].ConnectionString);
con.Open();
CheckBox CheckBox = row.FindControl("chkSelect") as CheckBox;
if (CheckBox.Checked == true)
{
SqlCommand command = new SqlCommand("INSERT INTO CoursesEmployees(couID, empID)VALUES(@couID, @empID)", con);
command.Parameters.AddWithValue("couID", TextBox1.Text);
command.Parameters.AddWithValue("empID", CheckBox.Checked);
command.ExecuteNonQuery();
Response.Redirect("Decou.aspx");
}
con.Close();
}
}
ลองรันแล้วมันขึ้นแบบนี้อะค่ะ ต้องทำยังไงคะ เครียดมากเลย
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_CoursesEmployees_Employees". The conflict occurred in database "BD_Training", table "dbo.Employees", column 'empID'.
The statement has been terminated.