How to fill a DataGridView using Entity Model in VB.NET

Here is a quick way of filling up and displaying the records from a table in a DataGridView

This post assumes that you already have created a EntityModel in your project

My Entity Model is called SuperHREntities and I have a table called Employees in it

The trick is to you use the .ToArray() after your table name in the following example to display the records.  If you simply try to use db.Employees then the records will not be displayed.


Private Sub frmMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim db As New SuperHREntities
DataGridView1.DataSource = db.Employees.ToArray()

End Sub


 Click on the Image to see it in full screen.

How to fill DataGridViewUsing Entity Model