Click here to Skip to main content
11,415,074 members (75,678 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: LINQ database VB.NET entity , +
Hello,

I'm having some trouble with getting my forms to display the recently updated data. The weird thing is that this only happens on decimal, int, or other fields having to do with only numbers.

What happens is after the user makes whatever changes they need to make and then saves the new data it'll update it to the database, but the forms will still display the old data, until the application is completely shut down and then re-started. I know the database is being updated exactly like it should be, but the application just won't show the new changes and as I've already mentioned, this only happens with numeric fields. All other data in the application will be shown exactly how it should as long as its not a numeric data type.

One thing I have noticed is that the forms will show the correct data, if I declare it as a new form and then open it compared to just typing in the name of the form with .showdialog. The only problem with this is that, due to the nature of some of the forms in my project, declaring them as a new form would conflict with a nice amount of my code that is already in place.

My question is, what could possibly be causing something like this and what do I need to do to fix it?

Also, my code is written in Visual Basic, and I use LINQ to Entities for retrieving, updating, and deleting records. The database is stored in SQL Server 2008 R2.

Thanks for any and all help.
Posted 11-Oct-12 9:33am
Edited 29-Oct-12 8:31am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Whenever you are populating your forms, you should create a new repository context for the given entities so that the data is updated. If you have a static context you may not be seeing the changes if they are saved under another context.
  Permalink  
Comments
Mr.McCloud at 11-Oct-12 15:16pm
   
Hmmm...do you mean like:
"Dim Context as DataAccessLayer.Entities = New DataAccessLayer.Entities" ?

This is how I declare my context in every form. Except of course, with the actual names of the entities and such.
Marcus Kramer at 11-Oct-12 15:20pm
   
Yes. I wouldn't use a static variable for the life of the form, but rather an instance for each update so that the instance goes and gets the updated data. That is why it works when you close the form and create a new one.
Mr.McCloud at 11-Oct-12 15:21pm
   
Hmmm, I think I'm getting it. Do you mean then that instead of declaring it at the top, I should declare it in the actual procedure its being called in?

By the way, thanks for the help so far.
Marcus Kramer at 11-Oct-12 15:26pm
   
Absolutely. That way it is only alive for the scope in which it is required.
Mr.McCloud at 11-Oct-12 15:27pm
   
Alright, I've tried it and it works perfectly. Thanks for the help. Much appreciated.
Marcus Kramer at 11-Oct-12 15:29pm
   
You are very welcome.

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 9,200
1 OriginalGriff 7,512
2 Maciej Los 3,710
3 Abhinav S 3,298
4 Peter Leow 3,084


Advertise | Privacy | Mobile
Web03 | 2.8.150427.4 | Last Updated 29 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100