In this tutorial, I'll show you how to load data from database into DataGridView using Entity Framework in VB.NET
As you know, DataGridView control provides a powerful and flexible way to display data in a tabular format. You can use the DataGridView control to show read-only views of a small amount of data, or you can scale it to show editable views of very large sets of data.
To practice demo, we will create a new VB.NET Project, then add an entity framework model as shown below
enter your model name
Select EF Designer from database, then click Next.
Select version Entity Framework that you want to use, click Next
Select your table that you want to use, then enter your model namespace.
We will use Northwind database to play demo, you should read how to download and restore northwind database to sql server
Add a DataGridView control to your windows form application, then add a BindingSource to your DataGridView
Add code to handle Form_Load event as the following
Public Class Form1 Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Dim db As New NorthwindEntities EmployeeBindingSource.DataSource = db.Employees.ToList() End Sub End Class
Run your project