Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# SQL-Server WPF , +
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);
    dispatcherTimer.Start();
}
 
Now I don't know how to proceed further with the event handler to handle the newly updated data from the database.
dispatcherTimer_Tick
 
here is my select statement that is used to fill the datagrid.
 
private void Page_Loaded(object sender, RoutedEventArgs e)
       {
 
           try
           {
               String selectstatement = "select top 2 ItemID, ItemName,ConsumerName, Street, DOJ from ConsumarTB order by ItemID ";
               da = new SqlDataAdapter(selectstatement, con);
               ds = new DataSet();
               da.Fill(ds);
               dataGrid1.ItemsSource = ds.Tables[0].DefaultView;
 
           }
           catch (SqlException e)
           {
               Console.WriteLine(e.Message);
           }
 
       }
 
Kindly help, even if there is another approach.
Thanks!
Posted 21-Dec-12 4:37am

1 solution

Rate this: bad
good
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...
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 304
1 Maciej Los 285
2 Sergey Alexandrovich Kryukov 255
3 Shweta N Mishra 216
4 PIEBALDconsult 174
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,760


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 21 Dec 2012
Copyright © CodeProject, 1999-2014
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