FUNGSI INPUT, INPUT, UPDATE, CARI & DELETE APLIKA APL IKA SI SEDERHANA PADA VB.NET 2010 MENGGUNAKA N DATA BA BASE SE ACCES 2007 Ap Aplik likasi sederhana Data Base Karyawan
Gambar :Form.1 MODULE.1 Imports System.Data.OleDb Module Module1 Public conn As New OleDbConnection Public cmd As OleDbCommand Public rd As OleDbDataReader Public da As OleDbDataAdapter Public ds As New DataSet Public str As String Sub koneksi() str = "provider=microsoft.jet.oledb.4.0;data source=Dbanggota.mdb" conn = New OleDbConnection OleDbConnection(str) (str) If conn.State = ConnectionState ConnectionState.Closed .Closed Then conn.Open() End Sub End Module *) Jangan lupa Buat koneksi ke data Base…
FORM.1 (LOGIN DENGAN USERNAME DAN PASWORD) Imports System.Data.OleDb Public Class Form1 Private Sub Button1_Click(ByVal Button1_Click(ByVal sender As System.Object System.Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles Button1.Click If TextBox1.Text = "" Then MsgBox("Username MsgBox("Username Kosong" Kosong") ) ElseIf TextBox2.Text = "" Then MsgBox("Password MsgBox("Password Kosong" Kosong") ) Else If TextBox1.Text = "w" And TextBox2.Text = "s" Then MsgBox("Berhasil MsgBox("Berhasil Login" Login") ) Form2.Show() Form2 .Show() End If End If End Sub Private Sub Button2_Click(ByVal Button2_Click(ByVal sender As System.Object System.Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles Button2.Click Me.Close() Me .Close() End Sub Private Sub Form1_Load(ByVal Form1_Load(ByVal sender As System.Object System.Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles MyBase.Load MyBase.Load Call koneksi() End Sub End Class
Gambar : Form.2
FORM.2 ( INPUT INPUT DATA & SIMPAN ) Imports System.Data.OleDb Public Class Form2 Sub tampil() da = New OleDbDataAdapter OleDbDataAdapter( ("Select * from Tbanggota" Tbanggota", , conn) ds = New DataSet da.Fill(ds, "Tbanggota" "Tbanggota") ) DataGridView1.DataSource = (ds.Tables("Tbanggota" (ds.Tables("Tbanggota")) )) DataGridView1.ReadOnly = True End Sub Sub bersih() TextNama.Text = "" TextPangkat.Text = "" TextNrp.Text = "" TextLahir.Text = "" ComboBoxAgama.Text = "" TextTlp.Text = "" RichAlamat.Text = "" End Sub Sub simpan() Try Dim str As String str = "insert into Tbanggota values ('" & TextNama.Text & "','" & TextPangkat.Text & "','" & TextNrp.Text & "', '" & TextLahir.Text & "', '" & ComboBoxAgama.Text & "', '" & RichAlamat.Text & "','" & TextTlp.Text & "')" cmd = New OleDbCommand OleDbCommand(str, (str, conn) cmd.ExecuteNonQuery() MessageBox.Show( MessageBox .Show("Simpan "Simpan Data Siswa Berhasil Dilakukan" Dilakukan") ) Catch ex As Exception MessageBox.Show( MessageBox .Show("Simpan "Simpan data Gagal Dilakukan" Dilakukan") ) End Try End Sub Private Sub Form2_Load(ByVal Form2_Load(ByVal sender As System.Object System.Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles MyBase.Load MyBase .Load
Call koneksi() Call tampil() End Sub Private Sub Smp_Click(ByVal Smp_Click(ByVal sender As System.Object System.Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles Smp.Click Call simpan() Call tampil() End Sub Private Sub Clear_Click(ByVal Clear_Click(ByVal sender As System.Object System.Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles Clear.Click Call bersih() End Sub Private Sub Ttp_Click(ByVal Ttp_Click(ByVal sender As System.Object System.Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles Ttp.Click Me.Close() Me .Close() End Sub Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object System.Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles SaveToolStripMenuItem.Click Call simpan() Call tampil() End Sub Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object System.Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles ExitToolStripMenuItem.Click Me.Close() Me .Close() End Sub Private Sub InputDataToolStripMenuItem_Click(ByVal sender As System.Object System.Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles InputDataToolStripMenuItem.Click FCaridata.Show() FCaridata .Show() Me.Close() Me .Close() End Sub Private Sub InputDataToolStripMenuItem1_Click(ByVal sender As System.Object System.Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles InputDataToolStripMenuItem1.Click FUbahdata.Show() FUbahdata .Show() Me.Close() Me .Close() End Sub Private Sub HapusDataToolStripMenuItem_Click(ByVal sender As System.Object System.Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles HapusDataToolStripMenuItem.Click FHapus.Show() FHapus .Show() Me.Close() Me .Close() End Sub End Class
GAMBAR : FORM.3 FORM.3 (CARI DATA ) Imports System.Data.OleDb Public Class FCaridata Sub tampil() da = New OleDbDataAdapter OleDbDataAdapter( ("Select * from Tbanggota" Tbanggota", , conn) ds = New DataSet da.Fill(ds, "Tbanggota" "Tbanggota") ) DataGridView1.DataSource = (ds.Tables("Tbanggota" (ds.Tables("Tbanggota")) )) DataGridView1.ReadOnly = True End Sub Sub bersih() TextNama.Text = "" TextPangkat.Text = "" TextNrp.Text = "" TextLahir.Text = "" ComboBoxAgama.Text = "" TextTlp.Text = "" RichAlamat.Text = "" End Sub Sub cari() Try Dim kode = InputBox("Masukkan InputBox("Masukkan Nrp" Nrp") ) ds.Tables(0).PrimaryKey = New DataColumn DataColumn() () {ds.Tables(0).Columns("Nrp" "Nrp")} )} Dim row As DataRow row = ds.Tables(0).Rows.Find(kode) TextNama.Text = row("Nama" row("Nama") ) TextPangkat.Text = row("Pangkat" row("Pangkat") ) TextNrp.Text = row("Nrp" row("Nrp") )
TextLahir.Text = row("Lahir" row("Lahir") ) TextTlp.Text = row("Tlp" row("Tlp") ) ComboBoxAgama.Text = row("Agama" row("Agama") ) RichAlamat.Text = row("Alamat" row("Alamat") ) Catch ex As Exception MsgBox("Data MsgBox("Data Tidak Ada" Ada") ) End Try End Sub Private Sub Form3_Load(ByVal Form3_Load(ByVal sender As System.Object System.Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles MyBase.Load MyBase .Load Call koneksi() Call tampil() End Sub Private Sub Button2_Click(ByVal Button2_Click(ByVal sender As System.Object System.Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles Button2.Click Call bersih() End Sub Private Sub Button3_Click(ByVal Button3_Click(ByVal sender As System.Object System.Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles Button3.Click Call cari() Call tampil() End Sub Private Sub Button1_Click(ByVal Button1_Click(ByVal sender As System.Object System.Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles Button1.Click Form2.Show() Form2 .Show() Me.Close() Me .Close() End Sub End Class
GAMBAR : FORM.4 FORM.4 FORM.4 FORM.4 (UBAH DATA) Imports System.Data.OleDb Public Class FUbahdata Sub tampil() Call koneksi() da = New OleDbDataAdapter OleDbDataAdapter( ("Select * from Tbanggota" Tbanggota", , conn) ds = New DataSet da.Fill(ds, "Tbanggota" "Tbanggota") ) DataGridView1.DataSource = (ds.Tables("Tbanggota" (ds.Tables("Tbanggota")) )) DataGridView1.ReadOnly = True End Sub Sub ubah() Try Dim str As String str = "Update Tbanggota set Nama = '" & TextBox1.Text & "', Pangkat = '" & TextBox2.Text & "', Lahir = '" & TextBox4.Text & "', Alamat = '" & ComboBox1.Text & "', Agama = '" & RichTextBox1.Text & "', Tlp = '" & TextBox5.Text & "' where Nrp = '" & TextBox3.Text & "'" cmd = New OleDbCommand OleDbCommand(str, (str, conn) cmd.ExecuteNonQuery() MessageBox.Show( MessageBox .Show("Update "Update Data Siswa Berhasil Dilakukan" Dilakukan") ) Catch ex As Exception MessageBox.Show( MessageBox .Show("Update "Update Data Siswa Gagal Dilakukan" Dilakukan") ) End Try End Sub Sub cari() Try Dim kode = InputBox("Masukkan InputBox("Masukkan Nrp" Nrp") ) ds.Tables(0).PrimaryKey = New DataColumn DataColumn() () {ds.Tables(0).Columns("Nrp" "Nrp")} )} Dim row As DataRow row = ds.Tables(0).Rows.Find(kode) TextBox1.Text = row("Nama" row("Nama") ) TextBox2.Text = row("Pangkat" row("Pangkat") ) TextBox3.Text = row("Nrp" row("Nrp") ) TextBox4.Text = row("Lahir" row("Lahir") ) TextBox5.Text = row("Tlp" row("Tlp") )
ComboBox1.Text = row("Agama" row("Agama") ) RichTextBox1.Text = row("Alamat" row("Alamat") ) Catch ex As Exception MsgBox("Data MsgBox("Data Tidak Ada" Ada") ) End Try End Sub Sub bersih() TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" TextBox4.Text = "" ComboBox1.Text = "" TextBox5.Text = "" RichTextBox1.Text = "" End Sub Private Sub FUbahdata_Load(ByVal FUbahdata_Load(ByVal sender As System.Object System.Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles MyBase.Load MyBase .Load Call koneksi() Call tampil() End Sub Private Sub Button1_Click(ByVal Button1_Click(ByVal sender As System.Object System.Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles Button1.Click Call ubah() Call tampil() End Sub Private Sub Button3_Click(ByVal Button3_Click(ByVal sender As System.Object System.Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles Button3.Click Call bersih() End Sub Private Sub Button4_Click(ByVal Button4_Click(ByVal sender As System.Object System.Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles Button4.Click Me.Close() Me .Close() Form2.Show() Form2 .Show() End Sub Private Sub Button2_Click(ByVal Button2_Click(ByVal sender As System.Object System.Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles Button2.Click Call cari() Call tampil() End Sub End Class
GAMBAR : FORM.5 FORM.5 FORM.5 ( HAPUS DATA ) Imports System.Data.OleDb Public Class FHapus Sub tampil() Call koneksi() da = New OleDbDataAdapter OleDbDataAdapter( ("Select * from Tbanggota" Tbanggota", , conn) ds = New DataSet da.Fill(ds, "Tbanggota" "Tbanggota") ) DataGridView1.DataSource = (ds.Tables("Tbanggota" (ds.Tables("Tbanggota")) )) DataGridView1.ReadOnly = True End Sub Sub hapus() Try Dim str As String str = "Delete * from Tbanggota where Nrp = '" & TextBox3.Text & "'" cmd = New OleDbCommand OleDbCommand(str, (str, conn) cmd.ExecuteNonQuery() MessageBox.Show( MessageBox .Show("Data "Data Anggota Berhasil Dihapus" Dihapus") ) Catch ex As Exception MessageBox.Show( MessageBox .Show("Data "Data Anggota Gagal Dihapus" Dihapus") ) End Try End Sub Sub cari() Try Dim kode = InputBox("Masukkan InputBox("Masukkan Nrp" Nrp") ) ds.Tables(0).PrimaryKey = New DataColumn DataColumn() () {ds.Tables(0).Columns("Nrp" "Nrp")} )} Dim row As DataRow row = ds.Tables(0).Rows.Find(kode) TextBox1.Text = row("Nama" row("Nama") ) TextBox2.Text = row("Pangkat" row("Pangkat") ) TextBox3.Text = row("Nrp" row("Nrp") ) TextBox4.Text = row("Lahir" row("Lahir") ) TextBox5.Text = row("Tlp" row("Tlp") ) ComboBox1.Text = row("Agama" row("Agama") ) RichTextBox1.Text = row("Alamat" row("Alamat") ) Catch ex As Exception MsgBox("Data MsgBox("Data Tidak Ada" Ada") )
End Try End Sub Sub bersih() TextBox1.Text = "" TextBox2.Text = "" TextBox3.Text = "" TextBox4.Text = "" ComboBox1.Text = "" TextBox5.Text = "" RichTextBox1.Text = "" End Sub Private Sub FHapus_Load(ByVal FHapus_Load(ByVal sender As System.Object System.Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles MyBase.Load MyBase .Load Call koneksi() Call tampil() End Sub Private Sub Button2_Click(ByVal Button2_Click(ByVal sender As System.Object System.Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles Button2.Click Call cari() Call tampil() End Sub Private Sub Button1_Click(ByVal Button1_Click(ByVal sender As System.Object System.Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles Button1.Click Call hapus() Call tampil() End Sub Private Sub Button3_Click(ByVal Button3_Click(ByVal sender As System.Object System.Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles Button3.Click Call bersih() End Sub Private Sub Button4_Click(ByVal Button4_Click(ByVal sender As System.Object System.Object, , ByVal e As System.EventArgs System.EventArgs) ) Handles Button4.Click Me.Close() Me .Close() Form2.Show() Form2 .Show() End Sub End Class