Simple question:
How can I display labelbox fields have been bound to SQL database table fields as they change?
The fields are changing from other programs. I just want to have a simple WPF program that displays the change.
Kind of like a status bar with like 2 labelboxes. I can do it with a clock using something like this:
private void Window_Loaded(object sender, RoutedEventArgs e)
{
.....
DispatcherTimer dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = new TimeSpan(0, 0, 1);
dispatcherTimer.Start();
}
private void dispatcherTimer_Tick(object sender, EventArgs e)
{
// TimeBox is my label field
TimeBox.Content = DateTime.Now.ToLongTimeString();
}
How do I make the labels that are bound to a SQL table refresh itself when their data changes?
Thanks for any suggestions
- Rommel
Loading
Amit ChoudharyPosted Mar 7, 2011, 7:14 AM
I have one idea don't think its best but it can be one of the solution for your problem.
You can use sqldependency change nitifier for this.. enable your sqlserver database for cache dependency. so whenever the datachange in the table it'll trigger the call and update the status in SqlDependency object.
Try this out if it works.
On the other hand when you application loaded load the data in Datatable and then time to time load the data again from database in another table and compare both the datatables for newly added record. but it'll cost the performance as more round trips will increase.
:))
Thanks.
Rommel RajPosted Mar 8, 2011, 5:33 AM
Suthish NairPosted Mar 7, 2011, 2:52 PM
Jaganathan BantheswaranPosted Mar 7, 2011, 7:18 AM
You have to use the SqlDenpendency class.
For more details : http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldependency.aspx