views:

70

answers:

1

Hi,

I've added a date time picker to a form. Initially its value is set to the DB sever date and time. Once its value is set, I need it to automatically update itself so that it always shows the DB server Date and time. How can I do this? Do I have to develop a custom control?

Thanks in advance!

+2  A: 

You could set up a System.Windows.Forms.Timer that fires a timeout event every X seconds (200ms,500ms,1sec.. whatever) and in the event handler increment the DateTime of the picker by the timeout amount. This will gradually stray away from the DB server by small amounts because of inexact timing.

Alternatively you could set up the same timer instead of incrementing the time in your picker, you can keep requesting the latest DB server time and setting the picker to that.

If the main purpose is to maintain appearances I would use the first option, and then re-request the DB time only when I need the most up to date time for an operation of some sort.

filip-fku
First option is the ideal solution for my need. I needed it just for display purposes. Thanks filip!
Kavinda Gayashan