Monday, 19 October 2015

VB.NET :: Program Visual Basic Net Simpan Edit Hapus Record Pada Database Access


Program Visual Basic Net Simpan Edit Hapus Record Pada Database Access
Berita Terkait
Menampilkan Record Ke ComboBox Dengan Visual Basic Net 2008
Menampilkan Record Ke ComboBox Dengan Visual Basic Net 2008
Pencarian Record Data Database Access Menggunakan Visual Basic Net 2008
Pencarian Record Data Database Access Menggunakan Visual Basic Net 2008
Program Edit dan Hapus Data Database Access Dengan VB Net
Program Edit dan Hapus Data Database Access Dengan VB Net
Program Tambah Record Di Visual Basic Net 2008
Program Tambah Record Di Visual Basic Net 2008
Program Koneksi Database Access Dari Visual Basic Net 2008
Program Koneksi Database Access Dari Visual Basic Net 2008
Sore yang panas ini saya tak lupa untuk membagikan sedikit ilmu pemrograman visual basic net.
Pada artikel program visual basic net simpan edit hapus record pada database accesssaya membahas kumpulan program yang terpisah pada artikel :
menjadi satu program utuh, sehingga anda tinggal menyimpan data, atau edit data, atau hapus data.
Program juga dilengkapi dengan beberapa perintah untuk memodifikasi button saat melakukan penyimpanan data, pengeditan ataupun penghapusan.
Silahkan buat dahulu database access :
Nama Database : SmartSolution.Mdb
Nama Table : Buku
Field
1. Kode type Text
2. Judul type Text
3. Pengarang type Text
4. Penerbit type Text
Design Form Program Visual Basic Net Simpan Edit Hapus Record Pada Database Access 
Program Visual Basic Net Simpan Edit Hapus Record Pada Database Access
Ketikkan listing program visual basic net simpan edit hapus record pada database access berikut
Imports System.Data.OleDb
Public Class Form1
Public DB As OleDbConnection
Public CMD As OleDbCommand
Public ADP As OleDbDataAdapter
Public DR As OleDbDataReader
Public DS As New DataSet
Dim SQL As String
Public Sub OpenDB()
Dim LOKASI = “Provider=Microsoft.Jet.OLEDB.4.0;Data Source =E:DatabaseSmartSolution.mdb”
DB = New OleDbConnection(LOKASI)
If DB.State = ConnectionState.Closed Then
DB.Open()
End If
End Sub
Sub TampilRecordBuku()
‘ PERINTAH SELEC TAMBAH HURUF T
ADP = New OleDbDataAdapter(“SELEC * FROM Buku”, DB)
DS = New DataSet
ADP.Fill(DS, “Buku”)
DataGridView1.DataSource = DS.Tables(“Buku”)
End Sub
Sub ButtonBaru()
btnBaru.Enabled = True
btnSimpan.Enabled = False
btnEdit.Enabled = False
btnHapus.Enabled = False
btnBatal.Enabled = False
btnkeluar.Enabled = True
End Sub
Sub ButtonEdit()
btnBaru.Enabled = False
btnSimpan.Enabled = False
btnEdit.Enabled = True
btnHapus.Enabled = True
btnBatal.Enabled = True
btnkeluar.Enabled = False
End Sub
Sub ButtonSimpan()
btnBaru.Enabled = False
btnSimpan.Enabled = True
btnEdit.Enabled = False
btnHapus.Enabled = False
btnBatal.Enabled = True
btnkeluar.Enabled = False
End Sub
Sub HapusText()
Judul.Text = “”
Kode.Text = “”
Pengarang.Text = “”
Penerbit.Text = “”
Call ButtonBaru()
End Sub
Private Sub btnkeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnkeluar.Click
Me.Close()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call OpenDB()
Call HapusText()
Call TampilRecordBuku()
End Sub
Private Sub btnBaru_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBaru.Click
Call HapusText()
Kode.Focus()
End Sub
Private Sub Kode_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Kode.KeyPress
Dim tombol As Integer = Asc(e.KeyChar)
Dim xkode As String
If tombol = 13 Then
‘ PERINTAH SELEC TAMBAH HURUF T
SQL = “SELEC * FROM BUKU Where Kode='” & Kode.Text & “‘”
CMD = New OleDbCommand(SQL, DB)
DR = CMD.ExecuteReader
DR.Read()
If DR.HasRows = True Then
Judul.Text = DR.Item(1)
Pengarang.Text = DR.Item(2)
Penerbit.Text = DR.Item(3)
Call ButtonEdit()
MsgBox(“Data ditemukan !”)
Else
xkode = Kode.Text
Call HapusText()
Kode.Text = xkode
Call ButtonSimpan()
End If
Judul.Focus()
End If
End Sub
Private Sub btnBatal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBatal.Click
Call HapusText()
Kode.Focus()
End Sub
Private Sub btnHapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnHapus.Click
SQL = “DELETE FROM BUKU Where Kode='” & Kode.Text & “‘”
CMD = New OleDbCommand(SQL, DB)
CMD.ExecuteNonQuery()
Call btnBaru_Click(sender, e)
Call TampilRecordBuku()
End Sub
Private Sub btnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEdit.Click
SQL = “UPDATE Buku SET Judul='” & Judul.Text & “‘,” & _
” Pengarang='” & Pengarang.Text & “‘,” & _
” Penerbit='” & Penerbit.Text & “‘ ” & _
” Where Kode='” & Kode.Text & “‘”
CMD = New OleDbCommand(SQL, DB)
CMD.ExecuteNonQuery()
Call btnBaru_Click(sender, e)
Call TampilRecordBuku()
End Sub
Private Sub btnSimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSimpan.Click
SQL = “INSERT INTO BUKU(kode, judul, pengarang, penerbit) ” & _
” values(‘” & Kode.Text & “‘,'” & _
Judul.Text & “‘,'” & _
Pengarang.Text & “‘,'” & _
Penerbit.Text & “‘)”
CMD = New OleDbCommand(SQL, DB)
CMD.ExecuteNonQuery()
Call btnBaru_Click(sender, e)
Call TampilRecordBuku()
End Sub
End Class
Tag : Program Visual Basic Net Simpan Edit Hapus Record Pada Database Access, Belajar Bahasa Pemrograman, Bahasa Pemrograman Visual Basic Net, Tempat Download Program, program vb net

Bila bermanfaat silahkan share Program Visual Basic Net Simpan Edit Hapus Record Pada Database Access ini dengan teman anda, Terima kasih sebelumnya


Anda Harus Baca Artikel Ini

No comments:

Post a Comment