WPF dynamic database connection

Hi,

I have the following situation:
I have a WPF application that produces records in a database. In this application I want to open a window showing these records in a GridView or a ListView (which would be the best?). I want this window to update the GridView/ListView as soon as there is a change in the database. Which would be the best approach to accomplish this?

Best regards
RTSol
RTSolAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gene_CypCommented:
Showing data as a table, best way to go is gridview.
For a comprehensive help on Gridview with WPF you can check this article:
 http://www.codeproject.com/KB/WPF/WPFDataGridExamples.aspx
Now as for the DB, what you need is a trigger. Triggers pick up any attempt to insert, update or delete on a table and as a result you can have them do whatever it is you want them to do.
http://msdn.microsoft.com/en-us/library/ms189799.aspx 
0
RTSolAuthor Commented:
Hi,

One question - how can you make the WPF app aware of that the SQL trigger has fired?

-RTSol
0
Gene_CypCommented:
The short way is have your app query every "x amount of time" and check for the MAX update time.
What I mean is, a standard field in your tables should be "lastUpdated" or something appropriately named.
Have your WPF app query the DB checking the latest value and comparing it with its last value. If the two are different then an insert or update has been made. As you can see this is not perfect. It requires regular DB querying.
 
 
A BETTER way is to use an SQL Service Broker (MS Sql 2005 and later required) which can notify the app itself. Here are some helpful links:
http://msdn.microsoft.com/en-us/library/bb839489.aspx
http://www.developer.com/article.php/3640771
http://www.codeproject.com/KB/database/IntroServiceBroker.aspx
http://www.mssqltips.com/tip.asp?tip=1836 
 
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

mdan93Commented:
Maybe using an assembly stored procedure  that notify you application from sql or starting a process using xp_cmdshell but  i don't know if there any limitation of triggers running xp_cmdshell.
0
Gene_CypCommented:
Here is also an improved way of dealing with "method A":
http://discuss.fogcreek.com/joelonsoftware2/default.asp?cmd=show&ixPost=67962&ixReplies=14
It's for C++ but what interests you is the idea behind it. You can make a stored procedure that records which tables have been updated and have your WPF App query that look up table only (thus small table, fast query, hence querying the DB every minute or every few minutes - depending on your requirements -  won't tax the database.
 
Explore Method B though (the SQL Service Broker was build with this in mind)
0
RTSolAuthor Commented:
Thanks - SQL Service Broker is probably the way to go. I found a nice post about it here: http://eclipsed4utoo.com/blog/tag/c/
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.