Connect to MySQL Database using Visual Basic.NET

January 23, 2016 | By | Reply More

Hi, its time to play with Visual Studio (VB.NET) and MySQL Server. I want to use MySQL Server to store my data entry from Visual Basic.NET form. On this tutorial, I will show you how to connect to MySQL Database from VB.NET form. The best and easiest way to connect to MySQL Server is using Module. This module then can be easily used on other forms.

First of all, make sure you have MySQL Server up and running. I have created a simple tutorial to install MySQL Server on Ubuntu 15.04. Also, you must have MySQL Connector/Net installed on your Windows. You can download it from here.

Now open Visual Studio, create new solution and add MySQL.Data reference. You can do this by go to Project | Add References. Select Framework and look for MySQL.data.

mysql.data reference.png

Now we are ready to create a module. Go to Project | Add Module. Select module from the list and give a name to the module. For example “MySQLConnect”.

Now start coding on the new module.

Now create a new form with a single button to open the connection.

form connect mysqlDouble click the Connect button and insert this code

Run the program and connect to MySQL Database.

 

Tags: ,

Category: Programming, VisualBasic.NET

Leave a Reply