I have 2 tables
t1 - Categories Id Name
t2 - Products Id Name CategoryId
I have a foreign key and it`s working but when I want to run a Delete query (for example O keep getting an error because of the foreign key.)
ths is my code:
protected void dlCategory_DeleteCommand(object source, DataListCommandEventArgs e)
{
string Id = ((Label)e.Item.FindControl("Label1")).Text;
string SQL = "DELETE FROM Categories WHERE PrimaryKey=@ID;";
SqlCommand cmd = new SqlCommand(SQL, conn);
cmd.Parameters.AddWithValue("@ID", Id);
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
BindDL();
}
If I remove the foreign key it`s working just fine!