I am using Visual Studio 2022 (VB.Net) and SQL Server 2022 Express. I am not a programmer; I just like teaching myself coding and trying to learn.
I have a program, and I am trying to access the data in the table I created, but when I try to connect a DataGrid view to the table there is nothing there. See the screenshots.
If someone could give me a hint, it would be greatly appreciated.
Kevin
5
I had only the MySQL
at hand. Here is a working example of connecting and filling DataGridView1
. Maybe this will help you?
Imports MySql.Data.MySqlClient
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim connection = New MySqlConnection(
"server = localhost;" &
"port = 3306;" &
"database = sakila;" &
"user = root;" &
"password=********;")
connection.Open()
Dim adapter = New MySqlDataAdapter("select * from city", connection)
Dim ds = New DataSet()
adapter.Fill(ds)
DataGridView1.DataSource = ds.Tables(0)
connection.Close()
End Sub
End Class