2
I have this code to insert values into a table:
conn.Open();
comm.CommandText = @"INSERT INTO ArticleBarCode(Code, Code_Article, BarCode, CreatedBy, CreatedOn, ModifiedBy, ModifiedOn, IsDeleted)
VALUES (@code, @codearticle, @barcode, 1, @date, 1, @date, 0)";
comm.Parameters.AddWithValue("@code", next);
comm.Parameters.AddWithValue("@codearticle", code);
comm.Parameters.AddWithValue("@barcode", numbercode);
comm.Parameters.AddWithValue("@date", DateTime.Now);
comm.ExecuteNonQuery();
conn.Close();
But when I run it gives me this mistake:
The INSERT statement conflicted with the FOREIGN KEY Constraint "Fk_articlebarcode_article". The Conflict occurred in database "Cardozugestdb", table "dbo. Article", column 'Code'.
How can I fix this ?
How can I fix it then ?
– D C
inserting values that exist in the Article table. validate the values to make sure that it is an existing value
– Ricardo Pontual