Koneksi MySql Dengan VB.Net


1. Install vbnya
2. Download mysql odbc-nya, install
3. create database di mysql, misalnya infoonline
4. use infoonline ==> create table mahasiswa
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 ikhsanganteng, 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 mahasiswa
Public con As New ADODB.Connection
Public rsmhs 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 ikhsanganteng, ok, copy connection stringnya
con.Open “Provider=MSDASQL.1;Persist Security Info=False;Data Source=ikhsanganteng”
con.CursorLocation = adUseClient
End Sub
Public Sub seleksimhs()
Set rsmhs = New ADODB.Recordset
rsmhs.Open “select * from mahasiswa”, 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
seleksimhs
Set DataGrid1.DataSource = rsmhs
End Sub

Advertisements

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