You are on page 1of 6

Nama : Ulfa Yuliana

NIM : 4181612092
Matkul : Pemrograman Visual DotNet
Tugas Pertemuan 9

1. File pada Ms. Access 2010

2. File pada project Ms. Visual Studio 2010


 Tampilan

1
 Syntax
1. mdlConfig.vb

Imports System.Data.OleDb
Module mdlConfig
Public CONN As OleDbConnection
Public DA As OleDbDataAdapter
Public DS As DataSet
Public CMD As OleDbCommand
Public DR As OleDbDataReader

Sub KoneksiDB()
Try

CONN = New OleDbConnection("provider=microsoft.ace.oledb.12.0; data


source=datamhs.accdb")
CONN.Open()
'MsgBox("Koneksi Database SUKSES")

Catch ex As Exception

MsgBox(ex.Message)

End Try
End Sub
End Module

2. Form1.vb
Imports System.Data.OleDb

Public Class Form1

Sub KosongkanForm()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox1.Focus()
End Sub

Sub MatikanForm()
TextBox1.Enabled = False
TextBox2.Enabled = False
RadioButton1.Enabled = False
RadioButton2.Enabled = False
ComboBox1.Enabled = False
TextBox3.Enabled = False
DateTimePicker1.Enabled = False
TextBox4.Enabled = False
End Sub
2
Sub HidupkanForm()
TextBox1.Enabled = True
TextBox2.Enabled = True
RadioButton1.Enabled = True
RadioButton2.Enabled = True
ComboBox1.Enabled = True
TextBox3.Enabled = True
DateTimePicker1.Enabled = True
TextBox4.Enabled = True
End Sub

Sub TampilkanData()
Call KoneksiDB()
DA = New OleDbDataAdapter("select * from tbl_mhs", CONN)
DS = New DataSet
DA.Fill(DS)
DataGridView1.DataSource = DS.Tables(0)
DataGridView1.ReadOnly = True

End Sub

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


System.EventArgs) Handles MyBase.Load
Call MatikanForm()
Call TampilkanData()

End Sub

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


System.EventArgs) Handles Button5.Click
Me.Close()
End Sub

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


System.EventArgs) Handles Button1.Click
Call HidupkanForm()
Call KosongkanForm()
End Sub

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


System.EventArgs) Handles Button6.Click
Call MatikanForm()
Call KosongkanForm()
End Sub

3
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Or
ComboBox1.Text = "" Or DateTimePicker1.Text = "" Or TextBox4.Text = "" Then
MsgBox("Data Belum Lengkap !")
Exit Sub
Else
Call KoneksiDB()
CMD = New OleDb.OleDbCommand("select * from datamhs where NIM='" &
TextBox1.Text & "'", CONN)
DR = CMD.ExecuteReader
DR.Read()
If Not DR.HasRows Then
Call KoneksiDB()
Dim simpan As String
simpan = "insert into datamhs values('" & TextBox1.Text & "','" &
TextBox2.Text & "','" & RadioButton1.Text & "','" & RadioButton2.Text & "','" &
ComboBox1.Text & "','" & TextBox3.Text & "','" & DateTimePicker1.Text & "','" &
TextBox4.Text & "')"
CMD = New OleDb.OleDbCommand(simpan, CONN)
CMD.ExecuteNonQuery()
MsgBox("Input data SUKSES !")
Else

MsgBox("NIM sudah ada !")

End If

Call MatikanForm()
Call KosongkanForm()
Call TampilkanData()

End If
End Sub

Private Sub DataGridView1_CellMouseClick(ByVal sender As Object, ByVal e As


System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles
DataGridView1.CellMouseClick
On Error Resume Next
TextBox1.Text = DataGridView1.Rows(e.RowIndex).Cells(0).Value
TextBox2.Text = DataGridView1.Rows(e.RowIndex).Cells(1).Value
RadioButton2.Text = DataGridView1.Rows(e.RowIndex).Cells(2).Value
ComboBox1.Text = DataGridView1.Rows(e.RowIndex).Cells(3).Value
TextBox4.Text = DataGridView1.Rows(e.RowIndex).Cells(4).Value
DateTimePicker1.Text = DataGridView1.Rows(e.RowIndex).Cells(5).Value
TextBox3.Text = DataGridView1.Rows(e.RowIndex).Cells(6).Value

Call HidupkanForm()
TextBox1.Enabled = False

End Sub

4
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Then
MsgBox("Data Belum Lengkap !)
Exit Sub
Call KoneksiDB()
CMD = New OleDb.OleDbCommand("update datamhs set Nama_Mahasiswa='" &
TextBox2.Text & "',Jenis_Kelamin='" & RadioButton1.Text & "','" &
RadioButton2.Text & "',Agama='" & ComboBox1.Text & "',No_Telepon='" &
TextBox3.Text & "',Tanggal_Lahir='" & DateTimePicker1.Text & "',Alamat='" &
TextBox4.Text & "' where NIM='" & TextBox1.Text & "'", CONN)
CMD.ExecuteNonQuery()
MsgBox("Update data SUKSES !")

End If

Call MatikanForm()
Call KosongkanForm()
Call TampilkanData()

End Sub

Private Sub Button4_Click(sender As System.Object, e As System.EventArgs)


Handles Button4.Click
If TextBox1.Text = "" Then
MsgBox("Tidak ada data yang dihapus !")
Exit Sub
Else
Call KoneksiDB()
CMD = New OleDb.OleDbCommand("delete from datamhs where NIM='" &
TextBox1.Text & "'", CONN)
CMD.ExecuteNonQuery()
MsgBox("Hapus data sukses !")

Call MatikanForm()
Call KosongkanForm()
Call TampilkanData()

End If
End Sub
End Class

5
 Output

You might also like