Yth. Bapak Ir. Agus Suharto, M.kom
berikut saya jelaskan untuk aplikasi atau program yang telah saya buat untuk UAS
pertama-tama buat database di ms acces seperti ini :
setelah database dibuat, buat design di Visual studio 2012
setelah itu masukan source code nya :
Imports System.Data
Imports System.Data.OleDb
Public Class WebForm1
Inherits System.Web.UI.Page
Dim koneksi As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\LATIHAN01\dbmobil_uas.accdb"
Dim objekkoneksi As New OleDb.OleDbConnection(koneksi)
Dim xReader As OleDb.OleDbDataReader
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim koneksi As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\LATIHAN01\dbmobil_uas.accdb"
Dim objekKoneksi As New OleDbConnection(koneksi)
objekKoneksi.Open()
Dim tambah As String = "INSERT INTO tabelmobil values ('" & kodemobil.Text & "','" & namamobil.Text & "','" & merk.Text & "','" & tahun.Text & "','" & jenis.Text & "','" & harga.Text & "')"
Dim objCmd = New OleDbCommand(tambah, objekKoneksi)
objCmd.ExecuteNonQuery()
objekKoneksi.Close()
MsgBox("DATA BERHASIL DISIMPAN")
End Sub
Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Response.Redirect("formtabelmobil.aspx")
End Sub
Protected Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
kodemobil.Text = ""
namamobil.Text = ""
merk.Text = ""
tahun.Text = ""
jenis.Text = ""
harga.Text = ""
End Sub
Protected Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
If Not Len(kodebarangcari.Text) = 0 Then
objekkoneksi.Close()
objekkoneksi.Open()
Dim ocmd As New OleDb.OleDbCommand(" SELECT * FROM tabelmobil where KODE_MOBIL='" + kodebarangcari.Text + "'", objekkoneksi)
xReader = ocmd.ExecuteReader()
If xReader.HasRows Then
xReader.Read()
kodemobil.Text = xReader("KODE_MOBIL")
namamobil.Text = xReader("NAMA_MOBIL")
merk.Text = xReader("MERK")
tahun.Text = xReader("TAHUN_PEMBUATAN")
jenis.Text = xReader("JENIS")
harga.Text = xReader("HARGA")
Else
kodebarangcari.Text = "Mobil tidak ada"
Exit Sub
End If
End If
End Sub
Protected Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
Response.Redirect("transaksi.aspx")
End Sub
End Class
Imports System.Data.OleDb
Public Class WebForm1
Inherits System.Web.UI.Page
Dim koneksi As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\LATIHAN01\dbmobil_uas.accdb"
Dim objekkoneksi As New OleDb.OleDbConnection(koneksi)
Dim xReader As OleDb.OleDbDataReader
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim koneksi As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\LATIHAN01\dbmobil_uas.accdb"
Dim objekKoneksi As New OleDbConnection(koneksi)
objekKoneksi.Open()
Dim tambah As String = "INSERT INTO tabelmobil values ('" & kodemobil.Text & "','" & namamobil.Text & "','" & merk.Text & "','" & tahun.Text & "','" & jenis.Text & "','" & harga.Text & "')"
Dim objCmd = New OleDbCommand(tambah, objekKoneksi)
objCmd.ExecuteNonQuery()
objekKoneksi.Close()
MsgBox("DATA BERHASIL DISIMPAN")
End Sub
Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Response.Redirect("formtabelmobil.aspx")
End Sub
Protected Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
kodemobil.Text = ""
namamobil.Text = ""
merk.Text = ""
tahun.Text = ""
jenis.Text = ""
harga.Text = ""
End Sub
Protected Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
If Not Len(kodebarangcari.Text) = 0 Then
objekkoneksi.Close()
objekkoneksi.Open()
Dim ocmd As New OleDb.OleDbCommand(" SELECT * FROM tabelmobil where KODE_MOBIL='" + kodebarangcari.Text + "'", objekkoneksi)
xReader = ocmd.ExecuteReader()
If xReader.HasRows Then
xReader.Read()
kodemobil.Text = xReader("KODE_MOBIL")
namamobil.Text = xReader("NAMA_MOBIL")
merk.Text = xReader("MERK")
tahun.Text = xReader("TAHUN_PEMBUATAN")
jenis.Text = xReader("JENIS")
harga.Text = xReader("HARGA")
Else
kodebarangcari.Text = "Mobil tidak ada"
Exit Sub
End If
End If
End Sub
Protected Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
Response.Redirect("transaksi.aspx")
End Sub
End Class
==================================================================
untuk form transaksi source code nya sebagai berikut :
Imports System.Data
Imports System.Data.OleDb
Public Class transaksi
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim koneksi As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\LATIHAN01\dbmobil_uas.accdb"
Dim objekkoneksi As New OleDb.OleDbConnection(koneksi)
End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim bil1, bil2, hasil As Integer
bil1 = harga2.Text
bil2 = qty.Text
hasil = harga2.Text * qty.Text
total.Text = hasil
End Sub
Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim koneksi As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\LATIHAN01\dbmobil_uas.accdb"
Dim objekKoneksi As New OleDbConnection(koneksi)
objekKoneksi.Open()
Dim tambah As String = "INSERT INTO Transaksi values ('" & kodemobil2.Text & "','" & namamobil2.Text & "','" & merk2.Text & "','" & tahun2.Text & "','" & harga2.Text & "','" & qty.Text & "','" & total.Text & "')"
Dim objCmd = New OleDbCommand(tambah, objekKoneksi)
objCmd.ExecuteNonQuery()
objekKoneksi.Close()
MsgBox("DATA BERHASIL DISIMPAN")
End Sub
Protected Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Response.Redirect("WebForm1.aspx")
End Sub
Protected Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
kodemobil2.Text = ""
namamobil2.Text = ""
merk2.Text = ""
tahun2.Text = ""
qty.Text = ""
harga2.Text = ""
total.Text = ""
End Sub
End Class
Imports System.Data.OleDb
Public Class transaksi
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim koneksi As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\LATIHAN01\dbmobil_uas.accdb"
Dim objekkoneksi As New OleDb.OleDbConnection(koneksi)
End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim bil1, bil2, hasil As Integer
bil1 = harga2.Text
bil2 = qty.Text
hasil = harga2.Text * qty.Text
total.Text = hasil
End Sub
Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim koneksi As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\LATIHAN01\dbmobil_uas.accdb"
Dim objekKoneksi As New OleDbConnection(koneksi)
objekKoneksi.Open()
Dim tambah As String = "INSERT INTO Transaksi values ('" & kodemobil2.Text & "','" & namamobil2.Text & "','" & merk2.Text & "','" & tahun2.Text & "','" & harga2.Text & "','" & qty.Text & "','" & total.Text & "')"
Dim objCmd = New OleDbCommand(tambah, objekKoneksi)
objCmd.ExecuteNonQuery()
objekKoneksi.Close()
MsgBox("DATA BERHASIL DISIMPAN")
End Sub
Protected Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Response.Redirect("WebForm1.aspx")
End Sub
Protected Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
kodemobil2.Text = ""
namamobil2.Text = ""
merk2.Text = ""
tahun2.Text = ""
qty.Text = ""
harga2.Text = ""
total.Text = ""
End Sub
End Class
=================================================================
hasil nya bisa kita lihat sebagai berikut :
sekian untuk tugas uas saya terima kasih banyak :)