cara koneksi vb.net dengan database mysql menggunakan DSN ODBC

 

 

'koding ini dibuat di module ----------------
Imports System.Data.Odbc

 

Module Module1

Public CONN As OdbcConnection
Public da As OdbcDataAdapter
Public ds As DataSet
Public cmd As OdbcCommand
Public dr As OdbcDataReader

 

Public Sub Koneksi()

'Menggunakan DSN - ODBC
CONN = New OdbcConnection("dsn=its6rjdsn")

 

'Menggunakan String koneksi

CONN=NewOdbcConnection("Driver=MySQL ODBC 5.1 Driver; SERVER= localhost; UID=root; DATABASE= Mydb;PORT=3306")


CONN.Open()
End Sub
End Module

 

'koding ini dibuat di form ----------------------

Imports System.Data.Odbc

 

Public Class Pasien


Private Sub Pasien_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call Koneksi
da = New OdbcDataAdapter("select * from tblpasien", CONN)
ds = New DataSet
da.Fill(ds)
DataGridView1.DataSource = ds.Tables(0)
DataGridView1.ReadOnly=True
End Sub

End Class