0

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

4
  • If you're using Entity framework, why did you mark this as ado.net? Classic ado.net looks quite different and you need a different solution. So what is it? Ado.net or EF? Commented Apr 22, 2012 at 22:21
  • Oh ok, didn't knew that ! I wrote my first program today. My C# project contains a file Model1.edmx which is ADO .NET Entity Data Model. So I thought this is ADO .NET Commented Apr 22, 2012 at 22:24
  • EF is ORM on top of ado.net. With ado.net itself you would need to write actual SQL queries, manage connections etc. With EF (and similar ORMs), you focus on the logic part - getting results, managing relations, ..., while lower-level stuff is hidden from you most of the time. Commented Apr 22, 2012 at 22:34
  • Oh thanks Walter ! Actually haven't got any knowledge of that yet ! But it's good to know now. Thanks. Commented Apr 22, 2012 at 22:58

2 Answers 2

2

Are you calling context.SaveChanges()?

Sign up to request clarification or add additional context in comments.

3 Comments

No Sorry, I am not calling anything like that. I will try now and see what happens !
Thanks. That worked and solved my problem. By the way, where can I get I this type of information from? Books / MSDN etc.? Thank you for your help.
@VVV, precisely + video tutorials etc... But most of all - google. Endless source of goodies for every programmer ;)
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.