0% found this document useful (0 votes)
29 views6 pages

Database - Nama Database: Dbbiodata Tabel 1. Tabel Biodata

This document contains source code for two forms - form1 and form2 - written in Visual Basic that manage a student biodata database using MySQL. Form1 allows adding, updating, deleting and viewing student records with details like name, photo and date. Form2 displays a student's participation in activities by fetching data from a separate activities table and populating a grid. It also allows adding, deleting and updating activity records for a student. Both forms establish a connection to the MySQL database and use recordsets to execute queries and retrieve/store data.

Uploaded by

Kg Har
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views6 pages

Database - Nama Database: Dbbiodata Tabel 1. Tabel Biodata

This document contains source code for two forms - form1 and form2 - written in Visual Basic that manage a student biodata database using MySQL. Form1 allows adding, updating, deleting and viewing student records with details like name, photo and date. Form2 displays a student's participation in activities by fetching data from a separate activities table and populating a grid. It also allows adding, deleting and updating activity records for a student. Both forms establish a connection to the MySQL database and use recordsets to execute queries and retrieve/store data.

Uploaded by

Kg Har
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

uA1A8ASL

- nama uaLabase: dbb|odata


1A8LL
1. 1abel b|odata
2. 1abel keglaLan
uesaln Iorm1
uesaln Iorm2
Source Code form1
Dim koneksi As New MYSQL_CONNECTION
Dim rs As New MYSQL_RS
Private Sub CmdBrowse_Click()
Codi.Filter = "(*.jpg,*.bmp)|*.jpg;*.bmp"
Codi.ShowOpen
ImgPhoto.Picture = LoadPicture(Codi.FileName)
End Sub
Private Sub CmdHapus_Click()
If txtNIM = "" Or txtNama = "" Then
MsgBox "Cari datanya terlebih dahulu", vbInformation, "Informasi"
txtNIM.SetFocus
Else
pesan = MsgBox("Anda yakin akan menghapus?", vbQuestion +
vbOKCancel, "Hapus?")
If pesan = vbOK Then
koneksi.Execute "DELETE FROM biodata WHERE NIM ='" & txtNIM.Text &
"'"
txtNIM.Text = Empty
txtNama.Text = Empty
ImgPhoto.Picture = LoadPicture("")
End If
End If
End Sub
Private Sub CmdKegiatan_Click()
Form2.Show
Unload Me
End Sub
Private Sub CmdSimpan_Click()
On Error GoTo salah:
rs.CloseRecordset
rs.OpenRs "SELECT * FROM biodata", koneksi
With rs
.AddNew
.Fields("Nim") = txtNIM.Text
.Fields("nama") = txtNama.Text
.Fields("tgl") = DTP1.Value
If ImgPhoto.Picture = 0 Then
.Fields("photo") = ""
Else
.Fields("photo") = .ReadBinaryFromFile(Codi.FileName)
End If
.Update
txtNIM.Text = Empty
txtNama.Text = Empty
ImgPhoto.Picture = LoadPicture("")
End With
rs.CloseRecordset
Set rs = Nothing
Exit Sub
salah:
pesan = MsgBox("Simpan Data tidak berhasil!" & Err.Description,
vbInformation + vbOKOnly, "Peringatan")
End Sub
Private Sub CmdTampil_Click()
rs.CloseRecordset
rs.OpenRs "SELECT * FROM biodata where NIM=" & Val(txtNIM), koneksi
If rs.RecordCount = 0 Then GoTo kosong
txtNama.Text = rs.Fields("nama")
DTP1.Value = rs.Fields("tgl")
If rs.SaveBinaryToFile(rs.Fields("photo").Value, App.Path &
"\tempp.dat") Then
ImgPhoto.Picture = LoadPicture(App.Path & "\tempp.dat")
Kill App.Path & "\tempp.dat"
End If
rs.CloseRecordset
Set rs = Nothing
Exit Sub
kosong:
pesan = MsgBox("Data tidak ada", vbOKOnly, "Peringatan")
End Sub
Private Sub Cmdtutup_Click()
End
End Sub
Private Sub Cmdupdate_Click()
On Error GoTo salah
koneksi.Execute "DELETE FROM biodata WHERE NIM ='" & txtNIM.Text &
"'"
rs.CloseRecordset
rs.OpenRs "SELECT * FROM biodata", koneksi
With rs
.AddNew
.Fields("Nim") = txtNIM.Text
.Fields("nama") = txtNama.Text
.Fields("tgl") = DTP1.Value
If ImgPhoto.Picture = 0 Then
.Fields("photo") = ""
Else
.Fields("photo") = .ReadBinaryFromFile(Codi.FileName)
End If
.Update
txtNIM.Text = Empty
txtNama.Text = Empty
ImgPhoto.Picture = LoadPicture("")
End With
rs.CloseRecordset
Set rs = Nothing
Exit Sub
salah:
MsgBox "Update gagal", vbInformation, "Informasi"
End Sub
Private Sub Form_Load()
koneksi.OpenConnection "localhost", "root", "", "dbbiodata", 3306
End Sub
Source Code form2
Dim koneksi As New MYSQL_CONNECTION
Dim rs1 As New MYSQL_RS
Dim rs2 As New MYSQL_RS
Sub daftar()
rs2.CloseRecordset
rs2.OpenRs "select namakeg, tahun from kegiatan where nim='" &
txtNIM & "'", koneksi
Grid.ColWidth(0) = 500
Grid.ColWidth(1) = 6000
Grid.ColWidth(2) = 2000
Grid.TextMatrix(0, 0) = "No"
Grid.TextMatrix(0, 1) = "Nama Kegiatan"
Grid.TextMatrix(0, 2) = "Tahun"
If rs2.RecordCount > 0 And Not (rs2.EOF) Then
Grid.Rows = rs2.RecordCount + 1
Grid.Cols = rs2.FieldCount + 1
rs2.MoveFirst
Do
baris = baris + 1
Grid.Row = baris
Grid.TextMatrix(baris, 0) = baris
For kolom = 1 To rs2.FieldCount
Grid.TextMatrix(baris, kolom) = rs2.Fields(kolom - 1)
Next
rs2.MoveNext
Loop Until rs2.EOF
Else
Grid.Rows = 1
End If
End Sub
Private Sub CmdHapus_Click()
If txtNIM = "" Or txtNama = "" Then
MsgBox "Cari datanya terlebih dahulu", vbInformation, "Informasi"
txtNIM.SetFocus
Else
pesan = MsgBox("Anda yakin akan menghapus?", vbQuestion +
vbOKCancel, "Hapus?")
If pesan = vbOK Then
koneksi.Execute "DELETE FROM kegiatan WHERE NIM ='" & txtNIM.Text &
"' AND namakeg='" & txtnamakegiatan.Text & "' AND tahun='" &
txtTahun.Text & "'"
Frame1.Visible = False
daftar
End If
End If
End Sub
Private Sub CmdSimpan_Click()
On Error GoTo salah:
rs2.CloseRecordset
rs2.OpenRs "SELECT * FROM kegiatan", koneksi
With rs2
.AddNew
.Fields("Nim") = txtNIM.Text
.Fields("namakeg") = txtnamakegiatan.Text
.Fields("tahun") = Val(txtTahun.Text)
.Update
txtnamakegiatan.Text = Empty
txtTahun.Text = Empty
Frame1.Visible = False
End With
daftar
rs2.CloseRecordset
Set rs2 = Nothing
Exit Sub
salah:
pesan = MsgBox("Simpan Data tidak berhasil!" & Err.Description,
vbInformation + vbOKOnly, "Peringatan")
End Sub
Private Sub CmdTambah_Click()
Frame1.Visible = True
txtnamakegiatan.Text = ""
txtTahun.Text = ""
txtnamakegiatan.SetFocus
End Sub
Private Sub CmdTampil_Click()
txtNIM_KeyPress (13)
End Sub
Private Sub Cmdtutup_Click()
Form1.Show
Unload Me
End Sub
Private Sub Form_Load()
Frame1.Visible = False
koneksi.OpenConnection "localhost", "root", "", "dbbiodata", 3306
End Sub
Private Sub Grid_DblClick()
posbrs = Grid.RowSel
Frame1.Visible = True
txtnamakegiatan.Text = Grid.TextMatrix(posbrs, 1)
txtTahun.Text = Grid.TextMatrix(posbrs, 2)
End Sub
Private Sub txtNIM_KeyPress(KeyAscii As Integer)
If KeyAscii = 13 Then
If txtNIM = "" Then
MsgBox "Isikan dulu yang akan ditampilkan!", vbInformation,
"Informasi"
Else
rs1.CloseRecordset
rs1.OpenRs "SELECT * FROM biodata where NIM=" & Val(txtNIM), koneksi
If rs1.RecordCount > 0 Then
txtNama.Text = rs1.Fields("nama")
If rs1.SaveBinaryToFile(rs1.Fields("photo").Value, App.Path &
"\tempp.dat") Then
ImgPhoto.Picture = LoadPicture(App.Path & "\tempp.dat")
Kill App.Path & "\tempp.dat"
End If
rs1.CloseRecordset
Set rs1 = Nothing
daftar
Else
MsgBox "NIM " & txtNIM & " Tidak Ada!", vbInformation, "Informasi"
End If
End If
End If
End Sub

You might also like