Skip to content

Koneksi VB 6 Mysql dengan ODBC

March 13, 2014

1.  Install vbnya
2.  Download mysql odbc-nya, install
3.  create database di mysql, misalnya tokomaximus
4.  use tokomaximus ==> create table barang
5.  masuk ke control panel, switch ke classic view aja.
6.  masuk ke Administrative Tools –> Data Source (ODBC)
7.  Di tag user DSN, klik Add
8.  pilih mysql odbc driver, –> klik finish
9.  akan tampil panel odbc connector
10. isi datasource name, misal maximus, description (kosongin juga boleh),server(defaultnya localhost),User nya root, password (default kosong), pilih databasenya
11. Klik Test… (success, connection was made) berarti telah sukses buat koneksi, klik ok
12. Sekarang, masuk ke vbnya, klik menu project — > references — > pilih Microsoft ActiveX  Data  Objects 2.0 Library dan Microsoft ActiveX Data Object RecordSet 2.8 Library
13. Di project Explorer, tambahkan module, add module
14. Isikan coding koneksi dan seleksi barang

Public con As New ADODB.Connection
Public rsbarang As New ADODB.Recordset

Public Sub konekdb()
Set con = New ADODB.Connection
‘ connection provider kalau ragu, ambil dari adodc,
‘build, isi bagian pada tag connection, isi datasource namenya,
‘pilih maximus, ok, copy connection stringnya
con.Open “Provider=MSDASQL.1;Persist Security Info=False;Data Source=maximus”
con.CursorLocation = adUseClient
End Sub

Public Sub seleksibarang()
Set rsbarang = New ADODB.Recordset
rsbarang.Open “select * from databarang”, con, adOpenDynamic, adLockOptimistic
End Sub

——————-
Kalau udah, di form, tambahkan komponen datagrid, double klik formnya
‘tambahkan coding berikut pada form_Load

Private Sub Form_Load()
konekdb
seleksibarang
Set DataGrid1.DataSource = rsbarang
End Sub

No comments yet

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

%d bloggers like this: