Reputation: 2758
I am using ADO.NET and trying to update a column value in a table in a SQL Server 2008 database. However the value is not updating. Even though it's update when I debug it in C# code. Here is my code:
using (ADONETClass context = new ADONETClass())
{
List<Invoices> list = context.Invoices.ToList<Invoices>();
foreach (Invoices b in list)
{
b.status = 0;
}
}
Now I debugged the code and saw that context.Invoices.ToList<Invoices>()[0].status
is indeed set to zero. But when the program finished running, I open the SQL Server Management Studio and status value there was still 0. Not sure what is going on? Am I missing something?
Thanks
Varun
Upvotes: 0
Views: 506
Reputation: 1990
Are you using Entity Framework? I think you're missing a call to context.SaveChanges In EntityFramework the changes are all just in memory and not written to database until you call SaveChanges
Upvotes: 1