Friday, 27 February 2015

Script Module Koneksi VB Mysql

Option Explicit
Public KonekDb As New ADODB.Connection
Public Rs_mhs As New ADODB.Recordset

Public SQLubah, SQLsimpan, SQLhapus As String

Sub BukaDatabase()
    Dim strSS, strPort, strDB, strUID, strPWD As String
   
            strSS = "localhost"
            strPort = "3306"
            strDB = "latihansqldb"
            strUID = "root"
            strPWD = ""
   
    Set KonekDb = New ADODB.Connection
    KonekDb.CursorLocation = adUseClient
   
KonekDb.ConnectionString = "" _
        & "DRIVER={MYSQL ODBC 3.51 Driver};" _
        & "SERVER=" & strSS & ";" _
        & "DATABASE=" & strDB & ";" _
        & "UID=" & strUID & ";" _
        & "PWD=" & strPWD & ";" _
        & "OPTION="
                   
    On Error Resume Next
    If KonekDb.State = adStateOpen Then
        KonekDb.Close
        Set KonekDb = New ADODB.Connection
        KonekDb.Open
    Else
        KonekDb.Open
    End If

    If Err.Number <> 0 Then
        MsgBox "GAGAL KONEKSI SERVER", vbOKOnly, "Kesalahan"
    End If

End Sub


No comments:

Post a Comment