I am currently working on a Windows Forms application using C#. I have two tables (tblBatch
& tblProduct
). These tables are related to each other based on the BatchID
.
i.e
-> tblBatch
BatchID
BatchName
And
-> tblProduct
ProductID
ProductName
BatchID
Now there are two different situations.
- Product registration (adding a specific item to the database - stalk quantity could be empty because this will just register a product.
- Supplying stalk quantity, updating the quantity amount of the products and assigning the
batchNo
to products.
At this point, the batchID
must already be present in the database before I would assign it to a product in tblProduct
. Because, product batch cannot be assigned before supply of products, and as during this stage, I don't have any supply which can give me an idea of the current batchNo
. So during product registration, I just want to assign null to the BatchID
in tblProduct
. Once a supply will be performed later, I will update this ID and will assign the exact BatchID
to the supplied Items.
However, I am getting the following error even I have tried keeping the BatchID
field null in tblProduct
but still I am unable to add record into the database.
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_tblProduct_tblBatch". The conflict occurred in database "myDB", table "dbo.tblBatch", column 'BatchID'.
Is there any solution to this problem? Or someone suggest me a simple way to resolve this specific problem.