Untuk mengisi waktu luang, saya mengajak Anda untuk menuangkan tulisan di dalam Aplikasi Visaul Basic.Net 2008, kali ini saya mengajak anda belajar VB.Net 2008 Lanjutan dimana pada VB.Net 2008 lanjutan ini kita akan membahasnya menggunakan database Acces. Pembelajaran ini saya dapatkan dari seorang guru besar dikampus saya yaitu : Bapak Mesran,S.KOM,M.KOM
Bagaimana caranya inilah program sederhana yang saya buat,dengan rincian :
1. Database Name : DBMahasiswa.mdb
2. Inilah gambarnya
Inilah Source Codenya :
Imports System.Data.OleDb
Public Class Form1
Dim db As OleDbConnection
Dim cmd As OleDbCommand
Dim adp As OleDbDataAdapter
Dim rs As OleDbDataReader
Dim ds As New DataSet
Dim sql As String
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
OpenDB()
TampilMHS()
Baru_Click(sender, e)
End Sub
Sub OpenDB()
Dim lokasi = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source =E:DBMahasiswa.mdb"
db = New OleDbConnection(lokasi)
If db.State = ConnectionState.Closed Then
db.Open()
End If
End Sub
Sub TampilMHS()
adp = New OleDbDataAdapter("Select * From Mahasiswa", db)
ds = New DataSet
adp.Fill(ds, "Mahasiswa")
DataGridView1.DataSource = ds.Tables("Mahasiswa")
End Sub
Private Sub Simpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Simpan.Click
sql = "Insert Into Mahasiswa (NPM,Nama,Jenjang,Jurusan,Semester)" & _
" Values('" & NPM.Text & "','" & _
Nama.Text & "','" & _
Jenjang.Text & "','" & _
Jenjang.Text & "','" & _
Semester.Text & "')"
cmd = New OleDbCommand(sql, db)
cmd.ExecuteNonQuery()
Baru_Click(sender, e)
Call TampilMHS()
End Sub
Private Sub Edit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Edit.Click
sql = "Update Mahasiswa Set Nama='" & Nama.Text & "'," & _
" Jenjang='" & Jenjang.Text & "'," & _
" Jurusan='" & Jurusan.Text & "'," & _
" Semester='" & Semester.Text & "'," & _
" Where NPM='" & NPM.Text & "'"
Try
cmd = New OleDbCommand(sql, db)
cmd.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message)
End Try
Call Baru_Click(sender, e)
Call TampilMHS()
End Sub