VB connect Ke MySQL

Posted on Updated on


Untuk mengkoneksikan VB ke MySQL perlu menginstal MyODBC (misalnya Versi 3.51). Ini contoh sederhana, pakai ADO , misal sudah diinstal database mysql dengan
host :localhost
database : Dbase1
user :root
password : m4sr1

Private Sub Command1_Click()
Dim konStr As String
Dim kon As ADODB.Connection
Dim rs as ADODB.Recordset

On Err GoTo errHandle

Set kon = New ADODB.Connection
Set rs=New ADODB.Recordset

konStr = “DRIVER={MySQL ODBC 3.51 Driver};” _
& “SERVER=localhost;” _
& “DATABASE=Dbase1;”

kon.CursorLocation = adUseClient
kon.Open myCOnStr, “root”, “m4sr1”

MsgBox “Koneksi sukses.”

‘ misal sudah ditambahkan DataGrid1 di Form , dan punya tabel daftaralamat di Dbase1

set rs=kon.Execute(“Select * From daftaralamat ” )
set DataGrid1.DataSource=rs.DataSource

Exit Sub

errHandle:
MsgBox Err.Number & ” ” & Err.Description

End Sub

Sumber:

http://www.diskusiweb.com/viewthread.php?tid=7337

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s