Membuat Koneksi Visual Studio Ke Ms.Access
Disini saya akan membuat Aplikasi sederhaha menggunakan Visual Studio Ultimate 2012, disini Aplikasi berbasis Web (Web Form asp.net) yang nantinya Data yang di buat pada Aplikasi tersebut akan tersimpan di Ms.Access
Ini Desain sederhana Aplikasi yang saya buat
Buat juga Tabel di Ms.Acccess sesuai dengan Aplikasi yang kita buat pada Visual Sutio
Jalankan Aplikasi dan masukan Datanya, lalu tekan tombol simpan, Jika sukses tekan tombol lihat
Data akan masuk ke Database Ms.Acces
Untuk dapat melihat Database, buat Web Form baru lalu Drag and Drop database yang sudah di buat ke Web Form baru tersebut
Ini Untuk semua Codingnya
Koneksi untuk Database Access
Imports System.Data
Imports System.Data.OleDb
Public Class UAS
Inherits System.Web.UI.Page
Dim Koneksi As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=E:\New folder (2)\Database\UAS.accdb"
Dim ObjKoneksi 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
Memunculkan Harga, Button Harga
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If DropDownList1.Text = ("11") Then
TextBox2.Text = ("3000")
ElseIf DropDownList1.Text = ("14") Then
TextBox2.Text = ("4000")
ElseIf DropDownList1.Text = ("19") Then
TextBox2.Text = ("5000")
ElseIf DropDownList1.Text = ("36") Then
TextBox2.Text = ("10000")
ElseIf DropDownList1.Text = ("74") Then
TextBox2.Text = ("20000")
ElseIf DropDownList1.Text = ("220") Then
TextBox2.Text = ("60000")
ElseIf DropDownList1.Text = ("275") Then
TextBox2.Text = ("75000")
ElseIf DropDownList1.Text = ("366") Then
TextBox2.Text = ("100000")
ElseIf DropDownList1.Text = ("966") Then
TextBox2.Text = ("250000")
ElseIf DropDownList1.Text = ("2010") Then
TextBox2.Text = ("500000")
ElseIf DropDownList1.Text = ("4804") Then
TextBox2.Text = ("1200000")
End If
End Sub
Membuat Diskon dan Bonus, Button Bayar
Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If TextBox2.Text >= 500000 Then
TextBox4.Text = (TextBox2.Text * 10 / 100)
TextBox5.Text = "Gratis Skin Permanen"
TextBox6.Text = TextBox2.Text - TextBox4.Text
Else
TextBox4.Text = "0"
TextBox5.Text = "Tidak Ada Bonus"
TextBox6.Text = TextBox2.Text
End If
End Sub
Menyimpan Data ke Database, Button Simpan
Protected Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
ObjKoneksi.Open()
Dim Tambah As String = "INSERT INTO UAS values('" & TextBox1.Text & "','" & DropDownList1.Text & "','" & TextBox2.Text &
"','" & DropDownList2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox6.Text & "')"
Dim oCmd = New OleDbCommand(Tambah, ObjKoneksi)
oCMD.ExecuteNonQuery()
ObjKoneksi.Close()
MsgBox("Succes")
End Sub
Menampilkan Data Pada Database, Button Lihat
Protected Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
Response.Redirect("WebFormView.aspx")
End Sub
Membersihkan Data, Button Bersih
Protected Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
TextBox1.Text = ""
DropDownList1.Text = ""
TextBox2.Text = ""
DropDownList2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
End Sub
Mencari Data pada Database, Button Cari
Protected Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
If Not Len(TextBox1.Text) = 0 Then
ObjKoneksi.Close()
ObjKoneksi.Open()
Dim oCmd As New OleDb.OleDbCommand("SELECT * FROM UAS Where ID Game='" + TextBox1.Text + "'", ObjKoneksi)
xReader = oCmd.ExecuteReader()
If xReader.HasRows Then
xReader.Read()
TextBox1.Text = xReader("ID Game")
DropDownList1.Text = xReader("Diamonds")
TextBox2.Text = xReader("Harga")
DropDownList2.Text = xReader("Pembayaran")
TextBox3.Text = xReader("No Telephone")
TextBox4.Text = xReader("Diskon")
TextBox5.Text = xReader("Bonus")
TextBox6.Text = xReader("Total Bayar")
Else
TextBox1.Text = "Data Tidak Ada"
Exit Sub
End If
xReader.Close()
End If
End Sub
End Class