I have a database table and I'm trying to update a cell with a money datatype (decimal) and I'm using LINQ and and Entity Framework.
Unfortunately Context.SaveChanges(); won't work for some reason.
Here is the table structure
Type Amount Machine
Cash 1000 Tablet
Here is my code:
using (var GC = new GroundCommanderEntities())
{
PAYMENT_Repo PAYMENTREPO = new PAYMENT_Repo();
var ExistingCashPayment = GC.PAYMENT_Repo
.Where(Filter => Filter.Type == "Cash" && Filter.Machine == "Tablet").ToList();
string type = "";
var amt = 0.00m;
foreach (var item in ExistingCashPayment)
{
type = item.Type;
amt = item.Amount;
}
if (type == cbPaymentType.Text) //a combobox that contains Types
{
PAYMENTREPO.Amount = amt + Convert.ToDecimal(txtTendering.Text);
GC.SaveChanges();
return true;
}
else
{
return false;
}
}
GC.SaveChanges();and look into the table, it didn't apply the change.foreachyou keep writing over the old values ofamtandtype? Is that the problem (Before anyone comments I know strings are immutable)amtandtypeeverytime in the loop. Really you should makeamtandtypea collection.