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

Form1 Oledbconnection Oledbdataadapter Oledbcommand Oledbdatareader Oledbdatareader Dataset

1. The document contains code for creating a login form in VB.NET that connects to an Access database and authenticates username and password entries. 2. It also includes code for a loading form that displays a progress bar while loading another form. 3. Additional code samples show forms for inputting, editing, and searching data in database tables, including connecting to the Access database and executing SQL queries.

Uploaded by

Luky Harefa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

Form1 Oledbconnection Oledbdataadapter Oledbcommand Oledbdatareader Oledbdatareader Dataset

1. The document contains code for creating a login form in VB.NET that connects to an Access database and authenticates username and password entries. 2. It also includes code for a loading form that displays a progress bar while loading another form. 3. Additional code samples show forms for inputting, editing, and searching data in database tables, including connecting to the Access database and executing SQL queries.

Uploaded by

Luky Harefa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Form Login

Imports System.Data.OleDb
Public Class Form1
Dim cn As OleDbConnection
Dim da As OleDbDataAdapter
Dim cmd As OleDbCommand
Dim rd As OleDbDataReader
Dim reader As OleDbDataReader
Dim ds As DataSet

Dim Query As String


Sub koneksi()
cn = New OleDbConnection("Provider=Microsoft.ACE.Oledb.12.0;Data Source=barang.AccDb")
If cn.State = ConnectionState.Closed Then
cn.Open()
End If
End Sub
Private Sub btncancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
btncancel.Click

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


Call koneksi()

End Sub

Private Sub btnlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


btnlogin.Click

Query = "Select * from Login Where Username='" & txtuser.Text & "' AND Password='" & txtpass.Text
& "'"
cmd = New OleDbCommand(Query, cn)
rd = cmd.ExecuteReader
If rd.HasRows Then

MsgBox("wellcome....")
Form2.Show()
Else
MsgBox("User atau Password Salah")
txtuser.Text = ""
txtpass.Text = ""
txtuser.Focus()
End If
End Sub

2. Form Loading
Public Class Form2

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Timer1.Tick
ProgressBar1.Increment(1)
Label1.Text = ProgressBar1.Value & ("%")
If ProgressBar1.Value = 100 Then
Me.Hide()
Frmbarang.Show()
Timer1.Stop()
End If
End Sub

Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


Timer1.Start()
End Sub
End Class

3. Form Input (Copykan Dari Import sampai Dataset (No. 1))


Sub Kosong()
txtkobar.Text = ""
txtnabar.Text = ""
txtjumlah.Text = ""
cmbjenis.Text = ""
txtkobar.Focus()

End Sub
Sub Tampil()
da = New OleDbDataAdapter("Select * from Biodata", cn)
ds = New DataSet
da.Fill(ds, "Biodata")
DGV.DataSource = ds.Tables("Biodata")
DGV.ReadOnly = True
End Sub
Sub Koneksi()
cn = New OleDbConnection("Provider=Microsoft.Ace.Oledb.12.0;Data Source=barang.Accdb")
If cn.State = ConnectionState.Closed Then
cn.Open()

End If
End Sub
Private Sub Frminput_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
Call Koneksi()
Call Tampil()
Call Kosong()

End Sub

Private Sub btnbatal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


btnbatal.Click
Kosong()
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 btnsimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


btnsimpan.Click
Dim Query As String
Query = "Select * from biodata Where kode_barang='" & txtkobar.Text & "'"
cmd = New OleDbCommand(Query, cn)
rd = cmd.ExecuteReader
If Not rd.HasRows Then
cmd = New OleDbCommand("Insert into Biodata Values('" & txtkobar.Text & "','" & txtnabar.Text
& "','" & txtjumlah.Text & "','" & cmbjenis.Text & "' )", cn)
cmd.ExecuteNonQuery()
MsgBox("Data Tersimpan....")
Call Tampil()
Call Kosong()
Else
MsgBox("Data yang di isikan sudah ada")
Call Kosong()

End If
End Sub
End Class

4. Form edit (Copykan Dari Import Sampai Sub Koneksi (No.3))


Private Sub FrmEdit_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call Koneksi()
Call Tampil()
Call Kosong()
End Sub
Private Sub DGV_CellContentClick(ByVal sender As System.Object, ByVal e As
System.Windows.Forms.DataGridViewCellEventArgs) Handles DGV.CellContentClick
Dim Cari As Integer = Nothing
Cari = DGV.CurrentRow.Index
With DGV
txtkobar.Text = .Item(0, Cari).Value
txtnabar.Text = .Item(1, Cari).Value
txtjumlah.Text = .Item(2, Cari).Value
cmbjenis.Text = .Item(3, Cari).Value
txtkobar.Enabled = False
End With
txtnabar.Focus()
End Sub

Private Sub btnbatal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


btnbatal.Click
Kosong()
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 btnubah_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


btnubah.Click
If txtkobar.Text = "" Then
MsgBox(" Jangan Dikosongkan")
Exit Sub
Else
Try
cmd = New OleDbCommand(" Update Biodata Set Nama='" & _txtnabar.Text & "' ,jumlah='" &
txtjumlah.Text & "' ,satuan='" & cmbjenis.Text & "' where kode_barang='" & _txtkobar.Text & "'", cn)
cmd.ExecuteNonQuery()
Call Tampil()
MsgBox("Data Berhasil Diubah")
Call Kosong()

Catch ex As Exception
MsgBox("Data gagal Diubah")
Call Kosong()

End Try

End If
End Sub

Private Sub btnhapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


btnhapus.Click
If txtkobar.Text = "" Then
MsgBox("Kode Barang Jangan Kosong")
Exit Sub
Else
If MessageBox.Show("Benar data DiHapus", "Pesan Hapus", MessageBoxButtons.YesNo) =
Windows.Forms.DialogResult.Yes Then
cmd = New OleDbCommand("Delete * from Biodata where kode_barang='" & txtkobar.Text & "'",
cn)
cmd.ExecuteNonQuery()
Call Tampil()
Call Kosong()
Else : Call Kosong()

End If

End If
End Sub
End Class
Private Sub btncari_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles btncari.Click
If ComboBox1.Text = "Kode Barang" Then
Call Koneksi()
cmd = New OleDbCommand("Select * from Biodata where kode_barang like '%" &
Txtcari.Text & "%'", cn)
rd = cmd.ExecuteReader
rd.Read()
If rd.HasRows Then
Call Koneksi()
da = New OleDbDataAdapter("Select * from Biodata where kode_barang like
'%" & Txtcari.Text & "%'", cn)
ds = New DataSet
da.Fill(ds, "Ketemu")
DGV.DataSource = ds.Tables("Ketemu")
DGV.ReadOnly = True
End If
End If
End Sub
End Class

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy