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

Form1 Oledbconnection Oledbcommand Dataset Oledbdataadapter Oledbdatareader

This document contains the code for a Windows form application written in Visual Basic .NET. It defines classes and subroutines to connect to an Access database, retrieve and display data in text boxes and a datagrid, add/edit records, and includes validation and other event handling code. The form is used to manage student attendance data by retrieving records based on instructor code, displaying the data, allowing edits, and saving changes back to the database.

Uploaded by

ShevSurahman
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views

Form1 Oledbconnection Oledbcommand Dataset Oledbdataadapter Oledbdatareader

This document contains the code for a Windows form application written in Visual Basic .NET. It defines classes and subroutines to connect to an Access database, retrieve and display data in text boxes and a datagrid, add/edit records, and includes validation and other event handling code. The form is used to manage student attendance data by retrieving records based on instructor code, displaying the data, allowing edits, and saving changes back to the database.

Uploaded by

ShevSurahman
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

Imports System.Data.

OleDb
Public Class Form1
Dim CONN As OleDbConnection
Dim CMD As OleDbCommand
Dim DS As New DataSet
Dim DA As OleDbDataAdapter
Dim RD As OleDbDataReader
Dim LokasiDB As String

Sub Koneksi()
LokasiDB = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Akademik.accdb"
CONN = New OleDbConnection(LokasiDB)
If CONN.State = ConnectionState.Closed Then
CONN.Open()
End If
End Sub
Sub Kosongkan()
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Clear()
TextBox7.Clear()
TextBox8.Clear()
TextBox9.Clear()
TextBox1.Focus()
End Sub

Sub TampilGrid()
DA = New OleDbDataAdapter("select * from Mahasiswa", CONN)
DS = New DataSet
DA.Fill(DS, "Mahasiswa")
DataGridView1.DataSource = DS.Tables("Mahasiswa")
DataGridView1.ReadOnly = True
CMD = New OleDbCommand("select * FROM Hari", CONN)
RD = CMD.ExecuteReader
Do While RD.Read
TextBox4.Items.Add(RD.Item(0))
Loop
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
Call Koneksi()
Call TampilGrid()
Call Kosongkan()
Label12.Text = Today
End Sub

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


System.Windows.Forms.KeyPressEventArgs)
If e.KeyChar = Chr(13) Then
Call Koneksi()
CMD = New OleDbCommand("Select * from Mahasiswa where Kode_Dosen='" &
TextBox1.Text & "'", CONN)
RD = CMD.ExecuteReader
RD.Read()
If Not RD.HasRows Then
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
TextBox9.Text = ""
TextBox2.Focus()
Else
TextBox2.Text = RD.Item("Nama_Dosen")
TextBox3.Text = RD.Item("Pertemuan")
TextBox4.Text = RD.Item("Hari")
TextBox5.Text = RD.Item("Tanggal")
TextBox6.Text = RD.Item("Waktu")
TextBox7.Text = RD.Item("Materi")
TextBox8.Text = RD.Item("Mahasiswa_Hadir")
TextBox9.Text = RD.Item("Mahasiswa_Tdk_Hadir")
TextBox2.Focus()
End If
End If
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button4.Click
TextBox1.MaxLength = 6
CMD = New OleDbCommand("Select * from Dosen where Kode_Dosen='" & TextBox1.Text &
"'", CONN)
RD = CMD.ExecuteReader
RD.Read()
If RD.HasRows Then
TextBox2.Text = RD.Item("Nama_Dosen")
Else
MsgBox("Kode tidak terdaftar")
TextBox1.Focus()
Exit Sub
End If
End Sub
Private Sub BtnTambah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles BtnTambah.Click
If TextBox1.Text = "" Or TextBox2.Text = "" Or TextBox3.Text = "" Then
MsgBox("Data belum lengkap")
Exit Sub
Else
Call Koneksi()

CMD = New OleDbCommand("Select * from Mahasiswa where Kode_Dosen='" &


TextBox1.Text & "'", CONN)
RD = CMD.ExecuteReader
RD.Read()
If Not RD.HasRows Then
Dim simpan As String = "insert into Mahasiswa values ('" & TextBox1.Text & "','" &
TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "','" &
TextBox6.Text & "','" & TextBox7.Text & "','" & TextBox8.Text & "','" & TextBox9.Text & "')"
CMD = New OleDbCommand(simpan, CONN)
CMD.ExecuteNonQuery()
MsgBox("Data Berhasil Disimpan", MsgBoxStyle.Information, "Information")
Else
Dim edit As String = "update Mahasiswa set Nama_Dosen='" & TextBox2.Text & "',
Pertemuan='" & TextBox3.Text & "',Hari='" & TextBox4.Text & "', Tanggal='" & TextBox5.Text & "',
Waktu='" & TextBox6.Text & "', Materi ='" & TextBox7.Text & "', & Mahasiswa_Hadir='" &
TextBox8.Text & "', Mahasiswa_Tdk_Hadir='" & TextBox9.Text & "' where Kode_Dosen='" &
TextBox1.Text & "'"
CMD = New OleDbCommand(edit, CONN)
CMD.ExecuteNonQuery()
MsgBox("Data berhasil di Edit", MsgBoxStyle.Information, "Information")
End If
Call Kosongkan()
End If
End Sub
Private Sub TextBox3_KeyPress(ByVal sender As Object,
System.Windows.Forms.KeyPressEventArgs)
If e.KeyChar = Chr(13) Then TextBox4.Focus()
End Sub
Private Sub TextBox4_KeyPress(ByVal sender As Object,
System.Windows.Forms.KeyPressEventArgs)
If e.KeyChar = Chr(13) Then TextBox5.Focus()
End Sub
Private Sub TextBox5_KeyPress(ByVal sender As Object,
System.Windows.Forms.KeyPressEventArgs)
If e.KeyChar = Chr(13) Then TextBox6.Focus()
End Sub
Private Sub TextBox6_KeyPress(ByVal sender As Object,
System.Windows.Forms.KeyPressEventArgs)
If e.KeyChar = Chr(13) Then TextBox7.Focus()
End Sub
Private Sub TextBox7_KeyPress(ByVal sender As Object,
System.Windows.Forms.KeyPressEventArgs)
If e.KeyChar = Chr(13) Then TextBox8.Focus()
End Sub

ByVal e As

ByVal e As

ByVal e As

ByVal e As

ByVal e As

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


System.EventArgs) Handles TextBox8.TextChanged
Dim f As Integer
f = 20
TextBox9.Text = f - Val(TextBox8.Text)
End Sub

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


System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellContentClick
End Sub
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TextBox1.Click
MsgBox("Mohon Masukan Kode Dosen A01 - A09", , "Perintah")
Exit Sub
End Sub
Private Sub BtnTampil_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles BtnTampil.Click
MsgBox("Data Ditampilkan", , "Informasi")
Call TampilGrid()
End Sub
Private Sub Button3_Click_2(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button3.Click
Dim Pilih = MsgBox("Apakah Anda Ingin Keluar ?", MsgBoxStyle.OkCancel +
MsgBoxStyle.Information, "Informasi")
If Pilih = MsgBoxResult.Ok Then
MsgBox("Terimakasi ", , "Informasi")
Close()
ElseIf Pilih = MsgBoxResult.Cancel Then
MsgBox("Kembali Lagi", MsgBoxStyle.Information, "Informasi ")
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Timer1.Tick
Label13.Text = TimeOfDay
End Sub
Private Sub TextBox4_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TextBox4.SelectedIndexChanged
End Sub
Private Sub TextBox3_KeyPress1(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress
Dim key As Integer = Char.ConvertToUtf32(e.KeyChar.ToString(), 0)
If Not (((key >= 48) And (key <= 57)) Or (key = 8)) Then
e.Handled = True
End If
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button5.Click, BtnTampil.Click

End Sub
End Class

You might also like