Click here to Skip to main content
16,012,821 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I don't understand why the changes doesn't get saved.
productID is set for primarykey for sure.

any ideas???

C#
public void UpdateProductSupplierUnitPrice(POrder order)
       {
           foreach (var item in order.POrderItems)
           {

               Product product = new Product
               {
                   ProductID = item.ProductID,
                   SupplierID = order.SupplierID,
                   UnitPrice = item.UnitPrice
               };
               masterRepository.SaveProduct(product);
           }
       }



C#
public void SaveProduct(Product product)
       {
           if (product.ProductID == 0)
           {
               product.CreatedBy = Convert.ToInt32(HttpContext.Current.User.Identity.Name);
               product.CreatedOn = DateTime.Now;

               productTable.InsertOnSubmit(product);
           }
           else
           {
               product.UpdatedBy = Convert.ToInt32(HttpContext.Current.User.Identity.Name);
               product.UpdatedOn = DateTime.Now;
           }

            productTable.Context.SubmitChanges();
       }
Posted

1 solution

C#
// Create a new Order object.
Order ord = new Order
{
    OrderID = 12000,
    ShipCity = "Seattle",
    OrderDate = DateTime.Now
    //
};
// Add the new object to the Orders collection.
db.Orders.InsertOnSubmit(ord);
// Submit the change to the database.
try
{
    db.SubmitChanges();
}
catch (Exception e)
{
    Console.WriteLine(e);
    // Make some adjustments.
    // ...
    // Try again.
    db.SubmitChanges();
}


Use above code as sample, try this way.
Hope this will help !!!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900