How to Update Multiple Items
You can use the Catalog System to update multiple items in a single operation. You can specify a collection of items to update. Alternatively, you can update items that match an expression. In either case, the number of items updated is returned.
To update multiple items
Get the set of data to update.
Set the property you want to update.
Use the UpdateItems method to update the items in the catalog.
Example
This example describes how to update items using two methods:
The first part of the example describes how to update the list price of all items in a category by using a bulk update operation. It first gets the category and a dataset of all items in the category. The example then iterates through the items to change the list price. It then updates all the items in a single operation.
The second part of the example describes how to update items that match an expression. The example creates an expression to find all items in the catalog that include "summer" in their descriptions. It then uses this expression to change a property value of these items in a single operation.
private static void UpdatePrice(CatalogContext context, ProductCatalog catalog, string categoryName)
{
// Update the price of all the products in a category.
// Get a category to search.
CatalogSearch search = context.GetCatalogSearch();
search.CatalogNames = catalog.Name;
search.SqlWhereClause = CatalogItemsDataSetSchema.CategoryName = categoryName;
CatalogItemsDataSet dataSet = search.Search();
// Iterate through the items in the category.
foreach (CatalogItemsDataSet.CatalogItem catalogItem in dataSet.CatalogItems)
{
// Add $5.00 to the price of each item.
catalogItem.ListPrice += 5;
}
// Update the items.
catalog.UpdateItems(dataSet);
}
private static void UpdateViaExpression(CatalogContext context, ProductCatalog catalog)
{
// Create an expression to find all items in the catalog with "Summer" in their descriptions.
string expression = @"Description Like '%summer%'";
// Update these items. Set property "OnSale" to "1".
catalog.UpdateItems(expression, "OnSale", 1);
}