Source code berikut untuk mengoneksikan MySQL dengan VB 6.
Menggunakan MySQL ODBC 3.51 Driver sebagai penghubung antara VB dan
MySQL nya.
Simpan source code berikut di Module :
Public Conn As New ADODB.Connection Public Sub koneksi() Dim ConnString As String Dim db_name As String Dim db_server As String Dim db_port As String Dim db_user As String Dim db_pass As String On Error GoTo buat_koneksi_Error db_name = "honorer" 'nama database anda db_server = "localhost" 'server database anda db_port = "3306" db_user = "root" 'username db anda db_pass = "" 'isi jika db anda menggunakan password 'ganti DRIVER berikut menjadi {MySQL ODBC 5.1 Driver}
jika ODBC yang anda gunakan versi 5.1 ConnString = "DRIVER={MySQL ODBC 3.51 Driver};SERVER=" & db_server & ";DATABASE=" & db_name & ";UID=" & db_user & ";PWD=" & db_pass & ";PORT=" & db_port & ";OPTION=3" If Conn.State = 1 Then Conn.Close With Conn .ConnectionString = ConnString .Open End With On Error GoTo 0 Exit Sub buat_koneksi_Error: MsgBox "Ada kesalahan dengan server, periksa apakah server sudah berjalan ! ", vbInformation, "Cek Server" End Sub
Private Sub Form_Load() koneksi End Sub
Jika membutuhkan ADODB Connection, gunakan variabel ‘Conn’ seperti contoh berikut :
rsAdo.Open
"select * from barang"
, Conn
0 komentar:
Posting Komentar