Aplikasi Sederhana Input Data (Visual Studio)
How Are You Mates?
Pada kesempatan kali ini saya akan memposting aplikasi sederhana input data menggunakan Visual Studio.
Tampilan WebFormView
Tampilan MS Acces
Tampilan setelah di RUN
Mengisi database
Tampilan database sudah terkoneksi ke MS Acces
Imports System.Data
Imports System.Data.OleDb
Public Class WebFormApplication1
Inherits System.Web.UI.Page
Dim Koneksi As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\ASUS X550Z\Documents\TabelDosen.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
(Button Simpan)
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
objekKoneksi.Open()
Dim tambah As String = "INSERT INTO TabelDosen values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "') "
Dim oCmd = New OleDbCommand(tambah, objekKoneksi)
oCmd.ExecuteNonQuery()
objekKoneksi.Close()
MsgBox("Sukses")
End Sub
(Button Cari)
Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If Not Len(TextBox1.Text) = 0 Then
objekKoneksi.Close()
objekKoneksi.Open()
Dim ocmd As New OleDb.OleDbCommand("SELECT * FROM TabelDosen where IDDosen='" + TextBox1.Text + "'", objekKoneksi)
Xreader = ocmd.ExecuteReader()
If Xreader.HasRows Then
Xreader.Read()
TextBox1.Text = Xreader("IDDosen")
TextBox2.Text = Xreader("NamaDosen")
TextBox3.Text = Xreader("MataKuliah")
TextBox4.Text = Xreader("Alamat")
Else
TextBox1.Text = "ID Tidak ada"
Exit Sub
End If
Xreader.Close()
End If
End Sub
(Button View)
Protected Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Response.Redirect("WebFormView.aspx")
End Sub
(Button Update)
Protected Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
objekKoneksi.Open()
Dim Rubah As String = "UPDATE TabelDosen set MataKuliah='" + TextBox3.Text + "' where IDDosen='" + Trim(TextBox1.Text) + "'"
Dim oCmd = New OleDbCommand(Rubah, objekKoneksi)
oCmd.ExecuteNonQuery()
objekKoneksi.Close()
MsgBox("Sukses")
End Sub
(Button Delete)
Protected Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox1.Focus()
End Sub
End Class
Pada kesempatan kali ini saya akan memposting aplikasi sederhana input data menggunakan Visual Studio.
- DESKRIPSI:
- SCREENSHOOT
Tampilan WebFormView
Tampilan MS Acces
Tampilan setelah di RUN
Mengisi database
Tampilan database sudah terkoneksi ke MS Acces
- SOURCE CODE:
Imports System.Data
Imports System.Data.OleDb
Public Class WebFormApplication1
Inherits System.Web.UI.Page
Dim Koneksi As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\ASUS X550Z\Documents\TabelDosen.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
(Button Simpan)
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
objekKoneksi.Open()
Dim tambah As String = "INSERT INTO TabelDosen values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "') "
Dim oCmd = New OleDbCommand(tambah, objekKoneksi)
oCmd.ExecuteNonQuery()
objekKoneksi.Close()
MsgBox("Sukses")
End Sub
Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If Not Len(TextBox1.Text) = 0 Then
objekKoneksi.Close()
objekKoneksi.Open()
Dim ocmd As New OleDb.OleDbCommand("SELECT * FROM TabelDosen where IDDosen='" + TextBox1.Text + "'", objekKoneksi)
Xreader = ocmd.ExecuteReader()
If Xreader.HasRows Then
Xreader.Read()
TextBox1.Text = Xreader("IDDosen")
TextBox2.Text = Xreader("NamaDosen")
TextBox3.Text = Xreader("MataKuliah")
TextBox4.Text = Xreader("Alamat")
Else
TextBox1.Text = "ID Tidak ada"
Exit Sub
End If
Xreader.Close()
End If
End Sub
(Button View)
Protected Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Response.Redirect("WebFormView.aspx")
End Sub
(Button Update)
Protected Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
objekKoneksi.Open()
Dim Rubah As String = "UPDATE TabelDosen set MataKuliah='" + TextBox3.Text + "' where IDDosen='" + Trim(TextBox1.Text) + "'"
Dim oCmd = New OleDbCommand(Rubah, objekKoneksi)
oCmd.ExecuteNonQuery()
objekKoneksi.Close()
MsgBox("Sukses")
End Sub
(Button Delete)
Protected Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox1.Focus()
End Sub
End Class
Komentar
Posting Komentar