0% found this document useful (0 votes)
24 views

"Provider Microsoft - Jet.OLEDB.4.0 Data Source " "/DB - Teman - MDB"

This document contains code for a form application that connects to an Access database to perform CRUD operations on a contacts table. It defines methods to connect to the database, clear form fields, display data in a grid, insert a new record, populate fields from a selected row, delete a record, and close the form. The form loads by calling methods to connect to the database and display the initial record set. Buttons trigger methods to save, delete, and exit while handling data selection populates the form fields.

Uploaded by

oz lombok
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

"Provider Microsoft - Jet.OLEDB.4.0 Data Source " "/DB - Teman - MDB"

This document contains code for a form application that connects to an Access database to perform CRUD operations on a contacts table. It defines methods to connect to the database, clear form fields, display data in a grid, insert a new record, populate fields from a selected row, delete a record, and close the form. The form loads by calling methods to connect to the database and display the initial record set. Buttons trigger methods to save, delete, and exit while handling data selection populates the form fields.

Uploaded by

oz lombok
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Imports System.Data.

OleDb
Public Class Form1
Public conn As New OleDbConnection
Public dtadapter As New OleDbDataAdapter
Public cmd As New OleDbCommand
Public Alamat, Perintah As String

Public Sub Bersih()


TextNomor.Clear()
TextNama.Clear()
TextAlamat.Clear()
TextTelepon.Clear()
TextEMail.Clear()
End Sub

Public Sub Koneksi()


Alamat = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
Application.StartupPath & "\Db_Teman.mdb"
conn = New OleDbConnection(Alamat)
End Sub

Public Sub Tampil_Grid()


Perintah = "Select*from Tb_Teman"
dtadapter = New OleDbDataAdapter(Perintah, conn)
Dim TableTEMAN As New DataTable
dtadapter.Fill(TableTEMAN)
DataGridView1.DataSource = TableTEMAN
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load
Koneksi()
Tampil_Grid()
End Sub

Private Sub ButtonSave_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles ButtonSave.Click
conn.Open()
Perintah = "insert into Tb_Teman Values('" & TextNomor.Text & "','" &
TextNama.Text & "','" & TextAlamat.Text & "','" & TextTelepon.Text & "','" &
TextEMail.Text & "')"
cmd = New OleDbCommand(Perintah, conn)
cmd.ExecuteNonQuery()
MsgBox("Tersimpan")
Tampil_Grid()
conn.Close()
End Sub

Private Sub DataGridView1_CellContentClick(ByVal sender As System.Object,


ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles
DataGridView1.CellContentClick
TextNomor.Text = DataGridView1.SelectedCells(0).Value
TextNama.Text = DataGridView1.SelectedCells(1).Value
TextAlamat.Text = DataGridView1.SelectedCells(2).Value
TextTelepon.Text = DataGridView1.SelectedCells(3).Value
TextEMail.Text = DataGridView1.SelectedCells(4).Value
End Sub
Private Sub ButtonDelete_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ButtonDelete.Click
conn.Open()
Perintah = "delete from Tb_Teman where Nomor='" & TextNomor.Text &
"'"
cmd = New OleDbCommand(Perintah, conn)
cmd.ExecuteNonQuery()
MsgBox("Yakin Dihapus")
Bersih()
Tampil_Grid()
conn.Close()
End Sub

Private Sub ButtonExit_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles ButtonExit.Click
End
End Sub
End Class

You might also like