【问题标题】:How to refresh WPF datagrid with dragged and dropped binding which contains database view?如何使用包含数据库视图的拖放绑定刷新 WPF 数据网格?
【发布时间】:2015-07-28 05:15:12
【问题描述】:

我有以下数据库结构。

Table:Books
Column: bookid;(PK)
Column: book_title;
Column: isbn;
Column: author_id;(FK)
Column: publisher_id;(FK)

上表通过外键与另外两个名为“publishers”和“authors”的表相连。它们的定义如下。

Table:Publishers
Column: publisher_id;(PK)
Column: publisher_title;


Table:Authors
Column: Author_id;(PK)
Column: Author_title;

我创建的数据库视图是:

view:book_info
Column: bookid;
Column: book_title;
Column: isbn;
Column: publisher_title;
Column: Author_title;

现在我所做的是,我将这个视图作为数据网格拖放到 WPF 窗口中。我得到所需的视图。我试图在绑定到表的简单网格上使用可观察集合。现在如何在将 ItemsSource 作为数据库视图的网格上使用这个 observable 集合?

我还没有写任何代码,因为我仍然困惑如何更新 并刷新此网格?

【问题讨论】:

    标签: c# wpf database datagrid observablecollection


    【解决方案1】:

    事情会以意想不到的方式发生。我的朋友发现即使进行了更新,实体也没有更新。所以我们创建了相同的新实体。请参阅下面的代码。

    //the first declaration on the top.
    bookDatabaseEntities bde = new bookDatabaseEntities();
    
    //wrote this code where i need to assign itemssource.This will fetch updates and overwrite older entity created earlier.
    bde = new bookDatabaseEntities();
    //asssign new view to the grid as itemssource
    joinViewsDataGrid.ItemsSource = bde.JoinViews;
    

    这对我有用,对我来说。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-15
      • 2011-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-21
      • 1970-01-01
      相关资源
      最近更新 更多