【问题标题】:Show data from Entity Framework into DataGridView将实体框架中的数据显示到 DataGridView
【发布时间】:2015-12-21 14:51:46
【问题描述】:

我想在 C# WinForm 中将 Entity Framework 中的数据显示到 DataGridView 中。 DataGridView 中的数据可以更改和更新到 sql 数据库。 谢谢

【问题讨论】:

    标签: c# entity-framework


    【解决方案1】:

    在 Google 上快速搜索一下,您可以找到很多示例:

    1) Example 1

    2) Example 2

    3)Example 3

    你可以在这里看到一个简单的例子:

    Context db = new Context();
    var data = (from d in db.tablename select d);
    dataGridView1.DataSource = data.ToList();
    

    理想情况下,您应该将数据库调用移动到一个单独的方法中,该方法位于业务类库或类似的东西中。但是为了使这个例子简单,我会让你自己弄清楚。

    关于更新网格中的数据,您可以search this on Google 并找到许多结果和详细教程。

    【讨论】:

    • 感谢您的回答 我的查询是:var query = (from ed in db_context.Ratings join sp in db_context.Students on ed.StudentID 等于 sp.IdStudent where ed.ExamDisciplineID == edis.IdExamDiscipline select new { sp.IdStudent, sp.Fullname, ed.Rating1, ed.Rating2 } ).Distinct().ToList(); dataGridView1.DataSource = 查询;我想更改 Rating1、Rating2 并更改数据表的更新。但是这个列是只读的
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-07
    • 1970-01-01
    • 2014-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多