How to get a C # Windows control to automatically update if the database table is updated / inserted?

I have a WinViewForms-C # listView that I linked to a database table (MySQL), but I cannot figure out how to get listView to automatically display the results when I make changes to the database table (update / insert), without having to fire an event. e.g. button_click, timer_tick, etc.

Can someone please call me in the right direction. Any advice / solutions would be greatly appreciated!

Thanks, -Donald

+3
source share
2 answers

SQL does not support sending change events from the database to the client.

DataTable . DataTable.

, :

  • - , 5 , ;

  • , . WCF, . ( ) WCF , . , .

, POP3. .

+1

, . , - , , , .

, , SQL , , , CRUD, , , , ,

EDIT 2

, Pieter, . , , (.. , WHERE key > last_key_receieved)

, , , . , View, , :

Timer updateScoresTimer = new Timer();
updateScoresTimer.Tick += delegate
{
    // 1. grab the database info
    // 2. filter for post-worthy changes
    // 3. iterate over changes, passing the UI info to AddScore(...)
};
updateScoresTimer.Interval = 30000;
updateScoresTimer.Start();

public delegate void AddScoreHandler(String arg1, String arg2, String arg3);
public void AddScore(String arg1, String arg2, String arg3)
{
    if (this.listView1.InvokeRequired)
        this.BeginInvoke(new AddScoreHandler(this.AddScore), new object[]{ arg1, arg2, arg3 });
    else
    {
        ListViewItem lvi = new ListViewItem(arg1);
        lvi.SubItems.AddRange(new string[]{ arg2, arg3 });
        this.listView1.Items.Add(lvi);
    }
}
0

Source: https://habr.com/ru/post/1776251/


All Articles