Click here to Skip to main content
11,920,772 members (59,080 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# SQL-Server WPF VS2010
I have a datagrid that displays a table which is bound to a sql server DB.
I would like to set a Timer for every 60 sec, that checks for any updation and then displays the latest updated data.

So far I have created a event_handler for datagrid, that includes the object dispatchertimer

private void dataGrid1_loaded(object sender, RoutedEventArgs e)
    DispatcherTimer dispatcherTimer = new DispatcherTimer();
    dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
    dispatcherTimer.Interval = new TimeSpan(0, 0, 60);

Now I don't know how to proceed further with the event handler to handle the newly updated data from the database.

here is my select statement that is used to fill the datagrid.

private void Page_Loaded(object sender, RoutedEventArgs e)
               String selectstatement = "select top 2 ItemID, ItemName,ConsumerName, Street, DOJ from ConsumarTB order by ItemID ";
               da = new SqlDataAdapter(selectstatement, con);
               ds = new DataSet();
               dataGrid1.ItemsSource = ds.Tables[0].DefaultView;
           catch (SqlException e)

Kindly help, even if there is another approach.
Posted 21-Dec-12 4:37am

1 solution

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

Solution 1

You have every 60 sec load data from db and compare it with you local copy , in case of any changes , you will need manually for each row change values according to new-one (for example by table key, lets assume that you have person with Id equals 1, and some one AFTER YOU LOAD DATA to Wpf app change his name , so get data from DB for each key fetch data from Db and compare values , if any changes do update!!)

One warning , this approach can lead to time consuming op, so perfom it in separate thread.
And i do not think that is so quite good solution...

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

  Print Answers RSS
0 OriginalGriff 548
1 Dave Kreskowiak 245
2 phil.o 170
3 KrunalRohit 134
4 F-ES Sitecore 130
0 OriginalGriff 6,778
1 KrunalRohit 4,530
2 Sergey Alexandrovich Kryukov 3,203
3 George Jonsson 2,815
4 Suvendu Shekhar Giri 2,181

Advertise | Privacy | Mobile
Web03 | 2.8.151120.1 | Last Updated 21 Dec 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