ADO网络如何绑定强制列表以更新其值 [英] How force list binded by ADO net to update its value

查看:109
本文介绍了ADO网络如何绑定强制列表以更新其值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WPF应用程序,它的调度程序每1秒就有一个tick事件,并且在tick函数中我调用函数,因此该函数将每秒运行一次,因此我将一个sqlite表绑定到list,该函数中的一些值数据库可能会更改,但是不幸的是,数据没有影响列表,这里是我的代码:

i have a WPF application has a dispatcher with tick event each 1 second and inside the tick function i call function, so the function will run each second,so i bind a sqlite table to list , inside the function some value on the database may change, unfortunately the data does not effected on the list , here my code:

   void windows1()

     Entity e = new Entity();
    
     private void Window_Loaded(object sender, RoutedEventArgs e)
      {
       startDigitalClocl();
       
      }

     void startDigitalClocl()
     {
     DispatcherTimer Timer = new DispatcherTimer();
     Timer.Interval = TimeSpan.FromSeconds(1);
     Timer.Tick += tickevent;
     Timer.Start();
     }

 public void tickevent(object sender, EventArgs e)
 {
     label_DWatch.Content = DateTime.Now.ToString(@"hh\:mm\:ss");
     var ReminderList = e. table.tolist();
     Alarm(ReminderList);

 }


void Alarm(List<Task> reminderList)
 {

  foreach (var Row in reminderList)
  {
   if (row.A1 ==0)
    {
     // do somthing :
      windows2 w = new windows2();
       w.show();
    }
   }
 }





在第二个窗口中,我更改了数据库值






and in the second window i did a change to the database value


Entity e = new Entity();
void dochang()
{
 var t= (e.table.Where(o => o.Id == id).FirstOrDefault());
 t.A1= "0";
 e.SaveChanges();
 this.Close();
}



我的问题是该值在列表中没有更改,但在数据库中已更改.
我如何强制列表更新其值.


我的问题是该值在列表中没有更改,但在数据库中已更改.
我如何强制列表更新其值.

我尝试过的事情:

我得到的唯一解决方案是在更改后强制应用程序重新启动,然后列表将更新值.



my problem is that the value does not change in the list but its changed on the database.
how i can force the list to update it''s value.


my problem is that the value does not change in the list but its changed on the database.
how i can force the list to update it''s value.

What I have tried:

the only solution i get is to force the application to restart after the change then the list will update the value

推荐答案

您必须重新获取数据.从技术上讲,您不应将模型直接绑定到视图.您应该绑定到中间视图模型.您需要添加更多代码来正确封送数据库访问权限.

您每秒都打数据库吗?您的应用如何有时间做其他事情?
You have to re-fetch the data. You technically shouldn''t be binding your model directly to the view. You should bind to an intermediary viewmodel. You have a lot more code to add to properly marshal database access.

You hit the database every second? How does your app have time to do anything else?


这篇关于ADO网络如何绑定强制列表以更新其值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆