Search code examples
c#frameworksentity

Show data from Entity Framework into DataGridView


I want show data from Entity Framework into DataGridView in C# WinForm. Data in DataGridView can change and update to sql database. Thanks


Solution

  • A quick search for this on Google and you can find many examples:

    1) Example 1

    2) Example 2

    3) Example 3

    You can see a simple example here:

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

    Ideally you should move the database call into a separate method, which is in a business class library or something similar. But for the purposes of keeping this example simple, I'll leave you to figure that out.

    With regards to updating data in the grid you can search this on Google and find many results and detailed tutorials.