Professional Documents
Culture Documents
NIM : 4181612092
Matkul : Pemrograman Visual DotNet
Tugas Pertemuan 9
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
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Module
2. Form1.vb
Imports System.Data.OleDb
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
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
End If
Call MatikanForm()
Call KosongkanForm()
Call TampilkanData()
End If
End Sub
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
Call MatikanForm()
Call KosongkanForm()
Call TampilkanData()
End If
End Sub
End Class
5
Output