First of all install mysql-connector-net-6.0.7 and follow this:
Right click on the program and add reference then browse then mysql.data.dll
then add module
Name it connection and copy this codes
Imports System
Imports System.Data
Imports MySql.Data.MySqlClient
Module connection
Public conn As New MySqlConnection
Public Sub ConnectDatabase()
Try
If conn.State = ConnectionState.Closed Then
conn.ConnectionString = "Server=Dell-PC;Data Source=localhost:3306;Database=dbquicklend;User ID=root;"
conn.Open()
End If
Catch myerror As Exception
MsgBox("Error in Database Connection", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly, "Error")
End Try
End Sub
Public Sub DisconnectDatabase()
Try
conn.Close()
Catch myerror As MySql.Data.MySqlClient.MySqlException
End Try
End Sub
End Module
just call connectdatabase anywhere in the program you would like to connect or call disconnectdatabase when you need to disconnect