geovannefarell

Modul koneksi

Nov 13th, 2012
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public strkoneksi As String
  2. Public conn As New ADODB.Connection
  3. Public rsUser As New ADODB.Recordset
  4. Public Function Koneksi() As Boolean
  5. 'settingan koneksi
  6. On Error GoTo er
  7. 'koneksi string ke mysql konektor
  8. strkoneksi = "DRIVER={MySQL ODBC 5.1 Driver};SERVER=" & "localhost" & ";DATABASE=" & "latihan" & ";UID=" & "root" & ";PWD=" & "admin" & ";PORT=" & "3306" & ";OPTION=3"
  9.  
  10. If conn.State = adStateOpen Then conn.Close
  11.  
  12. conn.Open strkoneksi
  13. conn.CursorLocation = adUseClient
  14.  
  15.  
  16. 'buka tabel database
  17.    rsUser.Open "SELECT nama,Password FROM user", strkoneksi, adOpenKeyset, adLockOptimistic
  18.  
  19. If conn.State = adStateOpen Then
  20.     Koneksi = True
  21.     Exit Function
  22. Else
  23.     Koneksi = False
  24.     Exit Function
  25. End If
  26. Exit Function
  27.  
  28. er:
  29. Koneksi = False
  30.  MsgBox "Gagal Loading Database", vbInformation, "Database Error"
  31. End Function
  32. '==========================================================
Advertisement
Add Comment
Please, Sign In to add comment