I am making a windows form app program in C#, using Linq. I am trying to update a foreign key column, but I keep on getting the error of:
"Operation is not valid due to the current state of the object."
The message box of the error points to the line:
throw new System.Data.Linq.ForeignKeyReferenceAlreadyHasValueException();
I have used the following method to try update:
//Updates a Product
public void UpdateProduct(int productID, string productName, int categoryID, int supplierID, bool priceType, decimal costPrice, decimal retailPrice, bool inStock)
{
Product product = (from p in db.Products
where p.ProductId == productID
select p).Single();
product.Name = productName;
product.CategoryId = categoryID;
product.SupplierId = supplierID;
product.PriceType = priceType;
product.CostPrice = costPrice;
product.RetailPrice = retailPrice;
product.Stock = inStock;
db.SubmitChanges();
}
What is the problem? Thank you in advance!