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

Program Film Access 2007

1) The document describes a program to manage a film database using Visual Basic .NET and Microsoft Access 2007. 2) It includes code to create a database with a "Film" table, create the user interface with labels, textboxes and buttons, and connect to the Access database. 3) It also includes code for common form operations like adding, updating, deleting and searching for film records in the database.

Uploaded by

Mas Anto
Copyright
© Attribution Non-Commercial (BY-NC)
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)
42 views6 pages

Program Film Access 2007

1) The document describes a program to manage a film database using Visual Basic .NET and Microsoft Access 2007. 2) It includes code to create a database with a "Film" table, create the user interface with labels, textboxes and buttons, and connect to the Access database. 3) It also includes code for common form operations like adding, updating, deleting and searching for film records in the database.

Uploaded by

Mas Anto
Copyright
© Attribution Non-Commercial (BY-NC)
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

Page |1

PROGRAM DATA FILM DENGAN DATABASE ACCESS 2007


A. MEMBUAT DATABASE dan TABLE a. Buat database format Microsoft Access 2007 dengan nama : Film. b. Buat sebuah table dengan nama : Film dan struktur table sebagai berikut : Field Name Data Type IDFilm Text Judul Text Artis Text Genre Text Format Text Studio Text Tahun Text c. Simpan di folder bin pada program anda. Field Size 6 50 50 15 15 50 4 Keterangan Primary Key

B. MEMBUAT PROGRAM VISUAL BASIC.NET a. Buat form dengan layout seperti dibawah ini :

Page |2

b. Property Setting OBJECT Form1 GroupBox Label1 Label2 Label3 Label4 Label5 Label6 Label7 Textbox1 Textbox2 Textbox3 Textbox4 Textbox5 PROPERTY Name Text Text Text Text Text Text Text Text Text Name Name Name Name Name VALUE frmFilm Form Data Film Data Film Kode Film Judul Film Artis Genre Format Studio Tahun txtKode txtJudul txtArtis txtStudio txtTahun OBJECT Combo1 Combo2 Button1 PROPERTY Name Name Name Text Button2 Name Text Button3 Name Text Button4 Name Text Button5 Name Text DataGridView Name VALUE cboGenre cboFormat btnSimpan Simpan btnUpdate Update btnHapus Hapus btnBatal Batal btnKeluar Keluar dgFilm

c. Membuat Class clsKoneksi


Imports Microsoft.VisualBasic Imports System.Data.Sql Public Class ClsKoneksi Protected tblUser = New DataTable Protected SQL As String Protected Cn As OleDb.OleDbConnection Protected Cmd As OleDb.OleDbCommand Protected Da As OleDb.OleDbDataAdapter Protected Ds As DataSet Protected Dt As DataTable Public Function OpenConn() As Boolean Cn = New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=..\film.accdb;Persist Security Info=False;") Cn.Open() If Cn.State <> ConnectionState.Open Then Return False Else Return True End If End Function Public Sub CloseConn() If Not IsNothing(Cn) Then Cn.Close() Cn = Nothing End If End Sub

Page |3

Public Function ExecuteQuery(ByVal Query As String) As DataTable If Not OpenConn() Then MsgBox("Koneksi Gagal..!!", MsgBoxStyle.Critical, "Access Failed") Return Nothing Exit Function End If Cmd = New OleDb.OleDbCommand(Query, Cn) Da = New OleDb.OleDbDataAdapter Da.SelectCommand = Cmd Ds = New Data.DataSet Da.Fill(Ds) Dt = Ds.Tables(0) Return Dt Dt = Nothing Ds = Nothing Da = Nothing Cmd = Nothing CloseConn() End Function Public Sub ExecuteNonQuery(ByVal Query As String) If Not OpenConn() Then MsgBox("Koneksi Gagal..!!", MsgBoxStyle.Critical, "Access Failed..!!") Exit Sub End If Cmd = New OleDb.OleDbCommand Cmd.Connection = Cn Cmd.CommandType = CommandType.Text Cmd.CommandText = Query Cmd.ExecuteNonQuery() Cmd = Nothing CloseConn() End Sub End Class

d. Membuat Code frmFilm


Public Class frmFilm Dim SQL As String Dim Proses As New ClsKoneksi Dim tblFilm As DataTable Sub Data_Record() tblFilm = Proses.ExecuteQuery("Select * From [film] order by Judul asc") dgFilm.DataSource = tblFilm End Sub

Page |4
Private Sub frmFilm_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated cboGenre.Items.Add("Drama") cboGenre.Items.Add("Action") cboGenre.Items.Add("Horor") cboGenre.Items.Add("Komedi") cboGenre.Items.Add("Thriller") cboGenre.Items.Add("Dokumenter") cboGenre.Items.Add("Animasi") cboFormat.Items.Add("VHS") cboFormat.Items.Add("VCD") cboFormat.Items.Add("DVD") cboFormat.Items.Add("Blue Ray") Call NonAktif() End Sub Sub Bersih() txtKode.Text = "" txtJudul.Text = "" txtArtis.Text = "" txtStudio.Text = "" txtTahun.Text = "" cboFormat.Text = "" cboGenre.Text = "" txtKode.Enabled = True txtKode.Focus() Call Data_Record() btnSimpan.Enabled = False btnUpdate.Enabled = False btnHapus.Enabled = False btnBatal.Enabled = False btnKeluar.Enabled = True End Sub Private Sub btnHapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHapus.Click SQL = "Delete From [film] Where IDFilm = '" & txtKode.Text & "'" Proses.ExecuteNonQuery(SQL) MessageBox.Show("Data telah dihapus..!!", "Penghapusan Sukses", MessageBoxButtons.OK, MessageBoxIcon.Information) Call Bersih() End Sub Private Sub txtKode_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtKode.TextChanged If Len(txtKode.Text) < 6 Then Exit Sub tblFilm = Proses.ExecuteQuery("Select * From [film] Where IDFilm='" & txtKode.Text & "'") If tblFilm.Rows.Count > 0 Then 'MessageBox.Show("Data Karyawan Tidak Ditemukan..!!", "Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information) With tblFilm.Rows(0) txtKode.Text = .Item("IDFilm") txtJudul.Text = .Item("Judul") txtArtis.Text = .Item("Artis") cboGenre.Text = .Item("Genre")

Page |5
cboFormat.Text = .Item("Format") txtStudio.Text = .Item("Studio") txtTahun.Text = .Item("Tahun") End With Call Aktif() txtKode.Enabled = False txtJudul.Focus() btnSimpan.Enabled = False : btnKeluar.Enabled = True btnUpdate.Enabled = True : btnHapus.Enabled = True : btnBatal.Enabled = True Else Call Aktif() txtKode.Enabled = False txtJudul.Focus() btnSimpan.Enabled = True btnUpdate.Enabled = False : btnHapus.Enabled = False : btnBatal.Enabled = True End If End Sub Private Sub btnBatal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBatal.Click Call Bersih() Call NonAktif() End Sub Sub Aktif() txtJudul.Enabled = True txtArtis.Enabled = True txtStudio.Enabled = True txtTahun.Enabled = True cboGenre.Enabled = True cboFormat.Enabled = True End Sub Sub NonAktif() txtJudul.Enabled = False txtArtis.Enabled = False txtStudio.Enabled = False txtTahun.Enabled = False cboGenre.Enabled = False cboFormat.Enabled = False End Sub Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click SQL = "Update [film] Set Judul = '" & txtJudul.Text & "', Artis='" & txtArtis.Text & "', Genre = '" & cboGenre.Text & "', Format = '" & cboFormat.Text & "', Studio = '" & txtStudio.Text & "', Tahun = '" & txtTahun.Text & "' where IDFilm = '" & txtKode.Text & "'" Proses.ExecuteNonQuery(SQL) MessageBox.Show("Data telah diubah..!!", "Perubahan Data Sukses", MessageBoxButtons.OK, MessageBoxIcon.Information) Call Bersih() Call NonAktif() End Sub

Page |6

Private Sub btnKeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnKeluar.Click End End Sub Private Sub dgFilm_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles dgFilm.DoubleClick txtKode.Text = dgFilm.SelectedCells(0).Value btnSimpan.Enabled = False : btnUpdate.Enabled = True : btnHapus.Enabled = True btnBatal.Enabled = True : btnKeluar.Enabled = False End Sub Private Sub frmFilm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Call Bersih() End Sub Private Sub btnSimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSimpan.Click SQL = "Insert Into [film] Values ('" & txtKode.Text & "','" & txtJudul.Text & "','" & txtArtis.Text & "','" & cboGenre.Text & "','" & cboFormat.Text & "','" & txtStudio.Text & "','" & txtTahun.Text & "')" Proses.ExecuteNonQuery(SQL) MessageBox.Show("Data Baru telah disimpan..!!", "Penyimpanan Sukses", MessageBoxButtons.OK, MessageBoxIcon.Information) Call Bersih() End Sub End Class

You might also like