Berikut adalah tahapan untuk koneksi database mySql dengan Visual Basic /Net
1. Download Mysql Connector di link Website MySQL
kemudian klik 2x untuk install MySql Connector
2. Tambahkan MySql Connectot ke Visual Basic .Net
klik kanan pada References yang berada di solution Explorer - add reference
3. Buat Form untuk koneksi , tambahkan button, lalu double klik button biar menampilkan editor untuk mengisikan code :
Tambahkan sintax dibawah :
Imports MySql.Data.MySqlClient
Public Class Form1
Dim svr As String = "localhost"
Dim uid As String = "root"
Dim pwd As String = ""
Dim db As String = "databasename"
Dim myConn As New MySqlConnection
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
cConn.ConnectionString = "server= " + svr + "; user id=" + uid + "; password=" + pwd + "; database=" + db + ""
Try
cConn.Open()
MessageBox.Show("Koneksi berhasil")
cConn.Close()
Catch myerror As MySqlException
MessageBox.Show("Error Koneksi : " & myerror.Message)
Finally
cConn.Dispose()
End Try
End Sub
End Class
Atau bisa juga sintax seperti ini :
Imports MySql.Data.MySqlClient
Public Class Form1
Dim cConnAs New MySqlConnection
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
cConn.ConnectionString = "server=localhost; user=root; password=; database=dbMysql; allow user variables=true"
cConn.Open()
MessageBox.Show("Koneksi berhasil")
End Sub
End Class
Jalankan tekan F5, lalu klik button1, maka hasilnya