WPF dynamic database connection


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
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

Showing data as a table, best way to go is gridview.
For a comprehensive help on Gridview with WPF you can check this article:
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.
RTSolAuthor Commented:

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

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:

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
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

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.
Here is also an improved way of dealing with "method A":
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)
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/
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.