CheckBox chk;
Label lblID;
for (int i = 0; i <= GridView1.Rows.Count - 1; i++)
{
chk = (CheckBox)GridView1.Rows[i].FindControl("chkSelect");
lblID = (Label)GridView1.Rows[i].FindControl("empID");
if (chk.Checked)
{
string str = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlConnection conn = new SqlConnection(str);
string couID = TextBox1.Text;
conn.Open();
string commandtext = @"INSERT INTO CoursesEmployees(couID, empID) VALUES('" + TextBox1.Text + "','" + GridView1.SelectedIndex + "')";
SqlCommand com = new SqlCommand(commandtext, conn);
com.ExecuteNonQuery();
conn.Close();
Response.Redirect("AddEmp.aspx");
}
}
Error : 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.