Selamat malam sobat blogger untuk kali ini ekoninjarr.blogspot.com akan ngasih tutorial membuat Aplikasi Data Mahasiswa di VB Net Dengan Database Acces 2007. Kalau kemarin-kemarin pembahasan tentang Program Java Netbeans dan juga Program PHP, mungkin sobat bosen ya dengan data mahasiswa. Ya kan biar sobat bisa pilih membuat program atau aplikasi itu nggak hanya menggunakan satu bahasa pemrograman, bisa Java, Php, VB Net, Dhelpi, C++ dan lain-lain.
Oke dah sobat kita mulai saja yuaaaa....
Langkah pertama sobat harus buat databasenya dulu di Acces 2007, caranya buka Microsoft Acces 2007 lalu pilih Blank Database lalu File Name isi dengan dbmahasiswa. Pilih tempat untuk menyimpan databasenya misal di disk D, setelah itu klik Create. Perhatikan gambar berikut :
Lalu Table1 : Table klik kanan pilih Design New
Isi Table Name dengan tbmahasiswa, dan buat field-fieldnya seperti ini (lalu simpan):
Sekarang buka VB Net nya yuaa sob,,
Pilih File New Project-->Windows Forms Aplication-->Name isi DataMahasiswa-->lalu klik OK
Siapkan :
- Label 5 buah
- TextBox 4 buah
- DataGridView1 1 buah
- GroupBox 1 buah
- Button 4 buah
Klik form data mahasiswa 2 kali masukan kode berikut:
Imports System.Data.OleDb
Public Class Form1
Private kon As OleDbConnection
Private Sub bersih()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
End Sub
Private Sub grid()
Dim adr As New OleDbDataAdapter("select * from tbmahasiswa", kon)
Dim adt As New DataSet
adr.Fill(adt, "tbmahasiswa")
DataGridView1.DataSource = adt.Tables("tbmahasiswa")
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim koneksi As String = "provider=microsoft.jet.oledb.4.0;Data source=D:\STMIK INSAN PEMBANGUNAN\visual basic\dbmahasiswa.mdb"
kon = New OleDbConnection(koneksi)
If kon.State = ConnectionState.Closed Then
kon.Open()
End If
Call grid()
End Sub
Private Sub DataGridView1_AutoGenerateColumnsChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.AutoGenerateColumnsChanged
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsimpan.Click
Dim hapus As String = "insert into tbmahasiswa values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "')"
Dim cmd As New OleDbCommand(hapus, kon)
cmd.ExecuteNonQuery()
Call grid()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnhapus.Click
Dim hapus As String = "DELETE FROM tbmahasiswa WHERE nama='" & TextBox1.Text & "'"
Dim cmd As New OleDbCommand(hapus, kon)
cmd.ExecuteNonQuery()
Call grid()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncancel.Click
Me.Close()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click
Call bersih()
End Sub
Private Sub DataGridView1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.Click
TextBox1.Text = DataGridView1.SelectedCells(0).Value
TextBox2.Text = DataGridView1.SelectedCells(1).Value
TextBox3.Text = DataGridView1.SelectedCells(2).Value
TextBox4.Text = DataGridView1.SelectedCells(3).Value
End Sub
End Class
Public Class Form1
Private kon As OleDbConnection
Private Sub bersih()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
End Sub
Private Sub grid()
Dim adr As New OleDbDataAdapter("select * from tbmahasiswa", kon)
Dim adt As New DataSet
adr.Fill(adt, "tbmahasiswa")
DataGridView1.DataSource = adt.Tables("tbmahasiswa")
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim koneksi As String = "provider=microsoft.jet.oledb.4.0;Data source=D:\STMIK INSAN PEMBANGUNAN\visual basic\dbmahasiswa.mdb"
kon = New OleDbConnection(koneksi)
If kon.State = ConnectionState.Closed Then
kon.Open()
End If
Call grid()
End Sub
Private Sub DataGridView1_AutoGenerateColumnsChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.AutoGenerateColumnsChanged
End Sub
Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsimpan.Click
Dim hapus As String = "insert into tbmahasiswa values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "')"
Dim cmd As New OleDbCommand(hapus, kon)
cmd.ExecuteNonQuery()
Call grid()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnhapus.Click
Dim hapus As String = "DELETE FROM tbmahasiswa WHERE nama='" & TextBox1.Text & "'"
Dim cmd As New OleDbCommand(hapus, kon)
cmd.ExecuteNonQuery()
Call grid()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncancel.Click
Me.Close()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click
Call bersih()
End Sub
Private Sub DataGridView1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGridView1.Click
TextBox1.Text = DataGridView1.SelectedCells(0).Value
TextBox2.Text = DataGridView1.SelectedCells(1).Value
TextBox3.Text = DataGridView1.SelectedCells(2).Value
TextBox4.Text = DataGridView1.SelectedCells(3).Value
End Sub
End Class
Note: Untuk tombol simpan, add, hapus dan cancel seseuaikan dengan kodingnya yuaa sob biar nggak acak-acakan.
Nah ini sedikit tutorial tentang Aplikasi Data Mahasiswa di VB Net Dengan Database Acces 2007
Sekarang coba jalankan programnya Start Debugging atau tekan tombol F5 pada keyboard
Semoga bermanfaat...!!!
Aplikasi Data Mahasiswa di VB Net Dengan Database Access 2007
4/
5
Oleh
Unknown
1 comments:
Tulis commentsMau tanya (hapus, conn)
ReplyNah hapusnya itu declarasi dari mana ya ?
Makasih