Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
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
Updated 29-Oct-12 7:31am
v2

1 solution

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.
 
Share this answer
 
Comments
Mr.McCloud 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.
fjdiewornncalwe 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 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.
fjdiewornncalwe 11-Oct-12 15:26pm    
Absolutely. That way it is only alive for the scope in which it is required.
Mr.McCloud 11-Oct-12 15:27pm    
Alright, I've tried it and it works perfectly. Thanks for the help. Much appreciated.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900