MySQL/VS 2008 - Getting updates from server
Hi there!
I've been developing a client application wich gets some data from a MySQL server and populates it to a DataTable. The data is shown in a DataGridView. The DataTable needs to be updated every second, since the server data may change at any time. I've been wondering what is the best way to keep the DataTable up to date?
The way I've been doing it for a while now, is that I refresh the enitre DataTable every second. This means that I have to clear the DataTable every second, for then to repopulate it. It works in one way, but sometimes it can be problematic especially when the data is displayed in a DataGridView. For me it doesn't look like the best/most efficient way to do it. So for you experienced MySQL/VB.NET-people out there; What is the best way to keep a DataTable "up to date"?
Thanks!
Re: MySQL/VS 2008 - Getting updates from server
Add a LastModified column to the table if it doesn't already have one and set that to the current date and time each time a record is saved. You can then query the database for only records whose LastModified field is in the last second. Get the result of that query into a new DataTable and then use the DataTable.Merge method to merge it into the existing DataTable. This also means that you won't be able to delete any records but rather just flag them as Removed, Inactive or the like.
Re: MySQL/VS 2008 - Getting updates from server
Thanks! I will try something like that out :)