• September 23, 2021


Bring Technology Ideas with you

 How to connect VB.net with MYSQL Server Database

To connect with MySQL server database, .net application form need to install mysql connector into your window machine. To download the connector, please visit this link


    As the same with other .net programming, VB.net also need to have a connector to be installed as:

      After, you have installed in your machines, please go to Visual Studio and then Create a new project using Vb.net and select Windows Form Application then rename your project as you wish, after that click Ok

        In your project Solution Explorer, Right click on References –> Add References

          Then in References Manager, please go to Extensions–> Scroll down to find MySQL.Data then select it after that click OK

            Go back to your Form1 project and double click to add the code below in order to test connection to MySQL Server database from your VB.net code:

            Imports MySql.Data.MySqlClient
            Public Class DatabaseConnect
                Dim cn As MySqlConnection
                Private Sub DatabaseConnect_Load(sender As Object, e As EventArgs) Handles MyBase.Load
                    Dim conString As String = "server=localhost; userid=root; password=; database=hrm"
                    cn = New MySqlConnection(conString)
                        MsgBox("Database connected successfully", vbInformation)
                    Catch ex As Exception
                    End Try
                End Sub
            End Class

            Do not forget to using Imports MySql.Data.MySqlClient in the top of your Public Class after that click Start

              The result appeared:

                Related post