Hi DW,
I have some code that saves product category field values on products, but when i hit the Save() method my code gives me this error:
Errors while running pipeline : Message : Violation of PRIMARY KEY constraint 'EcomProducts$PrimaryKey'. Cannot insert duplicate key in object 'dbo.EcomProducts'. The statement has been terminated. Source : .Net SqlClient Data Provider Stack trace : at System.Data.Common.DbDataAdapter.UpdatedRowStatusErrors(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount) at System.Data.Common.DbDataAdapter.UpdatedRowStatus(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount) at System.Data.Common.DbDataAdapter.Update(DataRow[] dataRows, DataTableMapping tableMapping) at System.Data.Common.DbDataAdapter.UpdateFromDataTable(DataTable dataTable, DataTableMapping tableMapping) at System.Data.Common.DbDataAdapter.Update(DataSet dataSet, String srcTable) at System.Data.Common.DbDataAdapter.Update(DataSet dataSet) at Dynamicweb.eCommerce.Products.Product.SaveAndConfirm(String ProductID, String ProductVariantID, String ProductLanguageID, Boolean skipExtendedSave) at Dynamicweb.eCommerce.Products.Product.Save()
When weird this is that i get the product from the database using the API, so i don't understand why this error is being thrown.
Here's a section of my code, and it's the Save() method that triggers the error.
Dynamicweb.eCommerce.Products.Product product = Dynamicweb.eCommerce.Products.Product.GetProductByID(dbProduct.ProductID, dbProduct.ProductVariantID, dbProduct.ProductLanguageID); foreach (CategoryField categoryField in categoryFields) { string categoryFieldId = categoryField.SystemName; foreach (Integration.DAL.Objects.Field field in categoryField.Fields) { product.SetCategoryValue(categoryFieldId, field.SystemName, string.Join(",", field.Options)); } } if (product != null) product.Save();
My product exists in 3 languages, and the works on danish languages, but gives the error above on GB and US languages.
Do you have any ideas to what could be wrong?
// Martin