0

I have a datagridview bound to a table that is part of an Entity Framework model. A user can edit data in the datagridview and save the changes back to SQL. But, there is a stored procedure that can also change the data, in SQL, not in the datagridview. When I try to "refresh" the datagridview the linq query always returns the older cached data. Here's the code that I have tried using to force EF to return new data:

      // now refresh the maintenance datagridview data source
        using (var context = new spdwEntities())
        {
            var maintData =
                from o in spdwContext.MR_EquipmentCheck
                where o.ProdDate == editDate
                orderby o.Caster, o.Strand
                select o;
            mnt_DGV.DataSource = maintData;
        }

I've seen a number of posts suggesting this method, but it didn't work for me. When In debug, I can see that the SQL table has the updated data in it, but when this snippet of code runs, maintData has the old data in it.

I've had this problem with a couple of other datagridviews and I solved it with a really ugly work-around. I need to clean all of them up. So, I'd really appreciate any suggestions.

1
  • You instantiate a variable named context but then use spdwContext Commented Mar 25, 2014 at 13:46

1 Answer 1

1

You are not using the variable context that you just created. Instead your code uses some other variable spdwContext of unknown origin. Try changing this line

from o in spdwContext.MR_EquipmentCheck

to

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

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.