Basic code:
Buat file external :
Open
(App.Path & "\Conection.ini") For Output As #1
Print
#1, data yang disimpan
Close #1
'
format Conection.ini, format(.ini) bisa anda ganti sesuka anda misalkan
"Conection.rhm" atau "Conection.db" dan lain-lain
'jika anda merubah format filenya jangan
lupa menyamkan format x pada sub "ReadKoneksi"
Sub ReadKoneksi()
'MEMBACA FILE CONFIG CONEKSI DATABASE
On Error GoTo err
Open
(App.Path & "\Conection.ini")
For Input As #1
While Not EOF(1)
Input #1, judul
Data file =
Mid(judul, a + 1, Len(judul) - a)
Wend
Close #1
Exit Sub
err:
End Sub
Data file adalah variable penampung daya
yang dibaca dari file external
Tambahkan 1 form lagi dan sisipkan Adodc dan Datagrid
Pada form 1 even form load ketikkan kode
Private Sub Form_Load()
ReadKoneksi
KonekDatabase
'utuk window 7 tuliskan
Adodc1.ConnectionString = ConnString
'untuk window XP bias juga di tulis
'Adodc1.ConnectionString =
Conn.ConnectionString
Adodc1.RecordSource = "Nama_Tabel"
Set DataGrid1.DataSource = Adodc1
End Sub kenudian buat module
=====================
|| Buat module
=======================
Public Conn As
New ADODB.Connection
Public ConnString As String
Sub KonekDatabase()
On Error GoTo err
With Conn
.ConnectionString =
ConnString
.Open
End With
On Error GoTo 0
Exit Sub
err:
MsgBox "Ada kesalahan
dengan server, periksa apakah server sudah berjalan !", vbInformation,
"Cek Server"
End Sub
Public Sub CloseDB()
If Conn.State
= adStateOpen Or ConnSIAK.State =
adStateConnecting Then
Conn.Close
Set
Conn = Nothing
End If
End Sub
Sub ReadKoneksi()
'MEMBACA FILE CONFIG CONEKSI DATABASE
On Error GoTo err
Open
(App.Path & "\Conection.ini")
For Input As #1
While Not EOF(1)
Input #1, judul
ConnString =
Mid(judul, a + 1, Len(judul) - a)
Wend
Close #1
Exit
Sub
err:
End SubSetting koneksi Vb My SQL Server dengan file external.pdf
Project Conection Vb My SQL Server