Anda di halaman 1dari 2

www.konsultasivb.

com
Oleh : Uus Rusmawan
Hal - 1 -

MENYIMPAN FOTO KE DALAM DATABASE


1. Buatlah database dengan nama dbfoto.mdb
2. Buatlah tabel dengan nama tblanggota
3. Buatlah struktur tabel anggota sebagai berikut:

Field Type Size Keterangan


NIM Text 5 Primary Key
Nama Text 30
Lokasi Text 200
Foto OLE Object

4. Buatlah form dengan bentuk seperti gambar di bawah ini

Catatan :
 Tambahkan komponen Common Dialog dan PictureBox
 Commond dialog diberi nama DGL1
 PictureBox diberi nama PIC1
www.konsultasivb.com
Oleh : Uus Rusmawan
Hal - 2 -

5. Ketik koding berikut ini

Dim CONN As New ADODB.Connection


Dim RSANGGOTA As New ADODB.Recordset

Sub KONEKSi()
Set CONN = New ADODB.Connection
Set RSANGGOTA = New ADODB.Recordset
CONN.Open "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & App.Path &
"\DBFOTO.MDB"
End Sub

Private Sub cmdcarigambar_Click()


dlg1.ShowOpen
Text3 = dlg1.FileName
End Sub

Private Sub cmdsimpan_Click()


If Text1 = "" Or Text2 = "" Or Text3 = "" Then
MsgBox " DATA BELUM LENGKAP"
Exit Sub
Else
Call KONEKSi
SIMPAN = "INSERT INTO TBLANGGOTA(NIM,NAMA,LOKASI,FOTO) VALUES " & _
"('" & Text1 & "','" & Text2 & "','" & Text3 & "','" & Pic1 & "')"
CONN.Execute SIMPAN
Text1 = "": Text2 = "": Text3 = ""
End If
End Sub

Private Sub Form_Load()


Text3.Enabled = False
End Sub

Private Sub Text3_Change()


Pic1.Picture = LoadPicture(Text3)
End Sub

NB. Program ini perlu dilengkapi agar secure dan user frendly

Selamat mencoba

Anda mungkin juga menyukai