WPF live Update from database - wpf

I am building a multiuser WPF application (requirement is a desktop app), database SQL Server 2008.
There are two types of users.
The first type user will enter a record which would be stored in a table.
The second type user initially will be presented with a listbox with the records from the table. The requirement is that the listbox must be updated live (i.e. if a new record is entered by the first user the listbox must be updated).
Currently I have not yet implemented the Database functionality.
I am currently working with ObservableCollection and simulating this scenario.
I would like to know the best approach for achieving this.
Should i use a timer and keep querying the table? Is there a more efficient way?
Is this even possible (should I switch to ASP.NET?) ?
I would appreciate any suggestions and tips that you may have.

Try using SqlDependency, since it can raise an event (OnChange) in your code when the results of a query would change on the server (as the result of an INSERT or UPDATE from another user or process, for example)
An example of its use on CodeProject for a simple live chat application:
http://www.codeproject.com/KB/database/chatter.aspx

Related

Best approach to get notifications from database when table record changing in asp.net core web api

I'm working with asp.net-core 2.2 web api project with angular 7. In this I want to get notifications when a record inserting or updating in specific table. I read many of articles on it with sqldependancy class. But none of them didn't give me any satisfied answer. The thing I want to know is, are there any best approaches to do this work with another way. And if the best approach is,using sqldependecy how to combine it with EntityFramework core?
You could create an AFTER UPDATE TRIGGER on the table. Depending on how you want to get notified (SQL Mail for example) you could then code for it.
(on a personal note, I hate triggers but this is another way to do it)

BindingSource filter on related table

I am using vb.net WinForms with SQL Server 2014. I have a form with various textboxes and checkboxes I am populating from the database with a BindingSource. The two tables with the relevant info are called Channel and Setup. A setup can have many channels while a channel belongs to one setup. In the setup table I have a field called CurrentSetup which indicates the active setup with a bit. I need to show info only from the channels that belong to the active setup. I tried putting "CurrentSetup='True'" on the BindingSource, but that doesn't seem to work because all my data is coming from the ChannelBindingSource which can only read the foreign key (Setup_id) from the Setup table, but can't access the rest of the table it seems.
So to sum it up, my question is how can I filter a BindingSource based on a field from a related table?
I'd add to that that I'm using the Entity Framework (6), and I've read that BindingSources aren't even the recommended way to do this, but it's the only thing I've found that seems to work so far. If I'm way off base with this, and should be doing something else I'm open to that too. I just still find BindingSources in the current (VS 2013) Microsoft documentation.
If you're using EF then you should be getting only the data you want using LINQ to Entities. It would be something like this:
Dim currentChannels = context.Channels.Where(Function(c) c.Setup.CurrentSetup)
That will then give you a list of all the Channel entities related to the Setup that has its CurrentSetup set to True.

What is the best way to identify updated items in an in memory list?

I'm using Siaqodb for my client side database engine in a Sync Framework silverlight project. I've switched to siaqodb because microsofts client side solution loads the entire database into memory at once and, as such, has a hard time handling large data.
I've bound a list of SiaqodbOfflineEntity objects to a silverlight datagrid in order to create an editable datagrid. Unlike microsofts solution, you can't bind the database entries directly to the datagrid. You have to query the database and bind a list of in memory objects to the datagrid. This causes a problem in that the database isn't immediatly updated when the datagrid cell is changed. I'm trying to find the best way to handle updates to the database after a change in the cell. I can't just update each item to the database because the siaqodb engine will mark the item as dirty even if no change was made to the object. This will cause conflicts when trying to sync. holding a cached version of the original list and then comparing each property of each object to find which ones have changed seems like it would work, but seems to be a bit cumbersome. I've also tried looking at some of the datagrids events but RowEditEnded doesn't appear to fire when a cell is edited and CurrentCellChanged seems to fire whenever I switch rows (odd).
There's got to be a better solution to this. Anyone have any ideas?
So I've gotten this to work by changing my offline entity classes to implement iNotifyPropertyChange and I think this is a reasonable solution. I set the PropertyChanged event to a function that saves the object to the database. There is a VS package called notifypropertyweaver that will inject this code at compile time, reducing the amount of work needed to be done on auto-generated entity code.

Real time database query

We have a windows program written in vbasic(i think) and we are re-writing the same program in c#. In the old program there is a grid. When we click any cell and as soon as edit the cell content the data in database is changing. In our new program we couldn't find the way of doing that. So we added some buttons for database actions like update selected cell.
What is the best way to do that?
You can do this in c# too.Use a datagridview and to bind with the database so that change in the grid effect database see here
Out of seeing dozens of legacy ODBC frontends put together in Access I would strongly advice not to commit changes in the database at real time. Instead try to create a lightweight process that helps the users to keep their data's quality high.
If you want this kind of functionality you could have the real time changes saved in a different schema, a set of different tables or with a flag that tells that these rows are unverified edits by the user X.
Rasel already gave you a pointer how to do the functionality in C#.

Databases and Qt

I am building an application in Qt/QML.
I have a table view of the database (PostgreSQL).
Is there a way to dynamically refresh my table if there is any change in the database.
One no-so-efficient way to do it is to keep sending periodic SQL queries.
Is there any automatic way to keep my view refreshed?
I am open to use any other Database also if required.
Qt seems to support the NOTIFY mechanism of PostgreSQL databases. Googling for it it found some bug reports, so not sure of well implemented that is. Since I've never used it, I'll have to refer you to google.
If you use QSqlTableModel (or an editable subclass of QSqlQueryModel) with QTableView, any edits made will immediately be visible.

Resources