SQL Server
Imports System.Data.SqlClient
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Using connection As New SqlConnection(
"Server=localhost\SQLEXPRESS;" &
"Database=master;" &
"Trusted_Connection=True;")
Dim adapter As New SqlDataAdapter("select * from spt_values", connection)
Dim table As New DataTable
adapter.Fill(table)
DataGridView1.DataSource = table
End Using
End Sub
End Class
MySQL
Imports MySql.Data.MySqlClient
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Using connection As New MySqlConnection(
"server=localhost;" &
"port=3306;" &
"database=sakila;" &
"user=root;" &
"password=********;")
Dim adapter As New MySqlDataAdapter("select * from city", connection)
Dim table As New DataTable
adapter.Fill(table)
DataGridView1.DataSource = table
End Using
End Sub
End Class
DataGridViewor any other controls directly from a database. You use some data access technology to retrieve the data into a list of some sort and that list is the data source for the grid. You should learn about data access technologies in VB and WinForms first. You can use vanilla ADO.NET, as per the first comment above, or you can create a typedDataSet, or you can use Entity Framework, or you can use some other ORM. The choice is yours. Once you have such a data source, that can be used to populate your grid.