FORUM MAHASISWA UNIGHA
terima kasih anda telah mengunjungi forum ini
FORUM MAHASISWA UNIGHA

APRESIASI ILMU UNTUK MEMAJUKAN TEKNOLOGI DAN INFORMASI


You are not connected. Please login or register

Membuat MySQLConnection.dll di VB 6

Topik sebelumnya Topik selanjutnya Go down  Message [Halaman 1 dari 1]

1 Membuat MySQLConnection.dll di VB 6 on Mon 21 Sep - 16:21:17

jamal


Admin
Admin
mungkin bagi mereka yang pemahaman codingnya udah mahir tidak ada masalah dalam pengkodingan di VB, namum bagi yang pemula seperti saya sangat sulit untuk mengkoneksikan sebuah aplikasi luar untuk bisa jalan di VB, semoga artikel ini bermanfaat khususnya bagi para pemula
Langkah pertama kita buat dll-nya terlebih dahulu
1. Buka VB6
2. Buat Project DLL baru (File - ActiveX DLL - OK)
3. Beri nama Class1 dengan nama clsMySQLConnection
4. Ketik listing program berikut pada clsMySQLConnection
Option Explicit
Private strServer As String
Private strDatabase As String
Private strUID As String
Private strPWD As String
Private strPort As String
Private cnOpen As Boolean
Private cn As ADODB.Connection
Private DGError
Private cnString As String
‘open connection
Public Sub Open_Cn(ByVal nstrServer As String, ByVal nstrDatabase As
String, ByVal nstrUID As String, ByVal nstrPWD As String, ByVal
nstrPort As String)
On Error GoTo errhandler
strServer = nstrServer
strDatabase = nstrDatabase
strUID = nstrUID
strPWD = nstrPWD
strPort = nstrPort
Set cn = New ADODB.Connection
cn.CursorLocation = adUseClient
cnString = “Driver=MySQL ODBC 3.51 Driver;Server=” & strServer
& “;UID=” & strUID & “;PWD=” & strPWD &
“;Database=” & strDatabase & “;port=” & strPort
cn.Open cnString
cnOpen = True
Exit Sub
errhandler:
Call MsgBox(”Connection Error.”, vbOKOnly, “Error”)
strServer = “”
cnOpen = False
End Sub
‘re open connection
Public Sub Re_Open_Cn()
Call Close_Cn
Call Open_Cn(strServer, strDatabase, strUID, strPWD, strPort)
End Sub
‘close connection
Public Sub Close_Cn()
If cnOpen = True Then
cn.Close
Set cn = Nothing
cnOpen = False
End If
End Sub
‘ambil nama server
Public Property Get myStrServer() As String
myStrServer = strServer
End Property
‘memberi nama server
Public Property Let myStrServer(ByVal nstrServer As String)
strServer = nstrServer
End Property
‘ambil nama database
Public Property Get myStrDatabase() As String
myStrDatabase = strDatabase
End Property
‘memberi nama database
Public Property Let myStrDatabase(ByVal nstrDatabase As String)
strDatabase = nstrDatabase
End Property
‘ambil nama user
Public Property Get myStrUID() As String
myStrUID = strUID
End Property
‘memberi nama user
Public Property Let myStrUID(ByVal nstrUID As String)
strUID = nstrUID
End Property
‘memberi password
Public Property Let myStrWD(ByVal nstrPWD As String)
strPWD = nstrPWD
End Property
‘ambil port
Public Property Get myStrPort() As String
myStrPort = strPort
End Property
‘memberi port
Public Property Let myStrPort(ByVal nstrPort As String)
strPort = nstrPort
End Property
‘ambil connection
Public Property Get myStrConnection() As ADODB.Connection
Set myStrConnection = cn
End Property
5. Save Project dengan nama MySQLConnectionKami di foleder (Project MySQLConnection)
6. Make MySQLConnectionKami.dll dan simpan di folder (Project MySQLConnection\DLL)
7. Buat Form pemanggil, dengan mebuka VB 6 (File - New Project - VB Enterprise Edition Controls - OK)
8. Beri nama Form dengan frm_CobaMySQLConnection
9. Tambahkan 1 buah Listview dan Button
10. Beri nama Listview1 dengan lvAmbilData
11. Beri nama Button1 dengan nama cmd_AmbilData
12. Rekomendasikan MySQLConnectionKami.dll (Project - Reference - Browse File MySQLConnection.dll - OK)
13. Pada lvAmbilData rubah view-nya pada Properties dengan 3-lvwReport
14. Ketik listing program berikut ini pada Form frm_CobaMySQLConnection
Private ambilConnection As MySQLConnectionKami.clsMySQLConnection
Private rs As ADODB.Recordset
Private Sub cmd_AmbilData_Click()
On Error Resume Next
Dim i As Double
Dim j As Double
Dim k As Double
Set rs = New ADODB.Recordset
Set ambilConnection = New MySQLConnectionKami.clsMySQLConnection
ambilConnection.Open_cn “localhost”, “MySQL”, “root”, “badboyfuck”, “8080″
rs.Open “SELECT * FROM help_category h;”, ambilConnection.myStrConnection, adOpenDynamic
jmlhRecord = rs.RecordCount
If jmlhRecord > 0 Then
For i = 0 To rs.Fields.Count - 1
lvAmbilData.ColumnHeaders.Add , , rs.Fields(i).Name, 2000
Next i
For k = 0 To rs.RecordCount - 1
If IsNull(rs.Fields(0).Value) Then _
lvAmbilData.ListItems.Add , , “” Else lvAmbilData.ListItems.Add , , rs.Fields(0).Value
For j = 1 To rs.Fields.Count - 1
If IsNull(rs.Fields(1).Value) Then _
lvAmbilData.ListItems.Item(k + 1).ListSubItems.Add , , “” Else
lvAmbilData.ListItems.Item(k + 1).ListSubItems.Add , ,
rs.Fields(j).Value
Next j
rs.MoveNext
Next k
End If
rs.Close
ambilConnection.Close_cn
Set rs = Nothing
End Sub

Lihat profil user http://sigliboys.blogspot.com

Topik sebelumnya Topik selanjutnya Kembali Ke Atas  Message [Halaman 1 dari 1]

Permissions in this forum:
Anda tidak dapat menjawab topik