Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

C#
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.

C#
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

1 solution

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...
 
Share this answer
 

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