how to connect vb.net using windowsform application to mysql workbenck
Loading
how to connect vb.net using windowsform application to mysql workbenck
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Md AnsariPosted Jun 8, 2026, 9:09 AM
Hey! Yeah, I've done this before. It's actually not as scary as it sounds once you know the steps.
How to Connect VB.NET Windows Forms to MySQL Workbench
Step 1: Install the Connector
Download and install MySQL Connector/NET from the official MySQL website.
Step 2: Add Reference to Your Project
Right-click your project in Solution Explorer
Click Add ? Reference ? Assemblies ? Extensions
Check MySql.Data and click OK
Step 3: Import the Library
At the top of your form code, add:
vbnet
Step 4: Write the Connection Code
Use this inside a button click or form load event:
vbnet
Step 5: Test It
Run your app and trigger the connection. If you see "Connected!" you're all set. If not, double-check your password and database name.
Cynthia SathuragiriPosted Jun 8, 2026, 4:53 AM
To connect a VB.NET Windows Forms application to a MySQL database (created/viewed using MySQL Workbench), follow these steps:
1. Install MySQL Connector/NET
Download and install MySQL Connector/NET, or add the NuGet package:
Install-Package MySql.Data
2. Import the MySQL Namespace
Imports MySql.Data.MySqlClient
3. Create a Connection String
Dim connStr As String = "Server=localhost;Database=mydatabase;Uid=root;Pwd=password;"
Replace:
localhost ? MySQL server name/IP
mydatabase ? Your database name
root ? MySQL username
password ? MySQL password
4. Test the Connection
Imports MySql.Data.MySqlClient
Public Class Form1
Private Sub btnConnect_Click(sender As Object, e As EventArgs) Handles btnConnect.Click
Dim connStr As String = "Server=localhost;Database=mydatabase;Uid=root;Pwd=password;"
Using conn As New MySqlConnection(connStr)
Try
conn.Open()
MessageBox.Show("Connected Successfully!")
Catch ex As Exception
MessageBox.Show("Connection Failed: " & ex.Message)
End Try
End Using
End Sub
End Class
5. Retrieve Data from MySQL
Dim query As String = "SELECT * FROM tbl_asset_warranty"
Using conn As New MySqlConnection(connStr)
conn.Open()
Dim cmd As New MySqlCommand(query, conn)
Dim reader As MySqlDataReader = cmd.ExecuteReader()
While reader.Read()
MessageBox.Show(reader("asset_id").ToString())
End While
End Using
6. Display Data in a DataGridView
Dim query As String = "SELECT * FROM tbl_asset_warranty"
Using conn As New MySqlConnection(connStr)
Dim da As New MySqlDataAdapter(query, conn)
Dim dt As New DataTable()
da.Fill(dt)
DataGridView1.DataSource = dt
End Using
Pankajkumar PatelPosted Jun 1, 2026, 11:51 AM
Hi Tanya Dhiiza,
Following are basic steps to connect vb.net using windows form application to MySQL database:
Install and Run MySQL Database and Visual Studio
MySQL Server Connection Credentials (host, username, password, and database name)
Install MySQL Connector/NET - from MySQL official site and install
Create Windows Forms Application
Add References
Create Connection
Set Up MySQL Database and Table
Design Windows Form
Run Application
Below are two best articles with sample code example for connect vb.net using windows form application to MySQL database:
Create Connection String Using Visual Studio Windows Application
Basic CRUD in Visual Studio Windows form with Xampp phpmyadmin DB
Connection Code:
Glad to help! Please mark this answer as the accepted answer if it helped you out!
Justinben RonaldPosted May 20, 2026, 8:52 AM
Connecting a VB.NET Windows Forms application to MySQL is not difficult once you install the right connector. First, install MySQL Connector/NET from MySQL Official Website (fun games free). After that, open your Windows Forms project in Visual Studio and add a reference to
MySql.Data.dll.Next, create a connection string that matches your MySQL Workbench server settings. Example:
In this example,
localhostis the MySQL server,rootis the username, andtestdbis the database name created in MySQL Workbench. When you run the application and click the button, the program will attempt to connect to MySQL and display a success message if everything is configured correctly.