Listing Program Ado - Net & Validasi
Listing Program Ado - Net & Validasi
NET)
Imports System.Data.OleDb
Public Class Form1
Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=… \Databarang.Mdb")
Dim da As New OleDbDataAdapter("Select * from Barang", cn)
Dim dt As New DataTable
Dim ds As New DataSet
Dim cm As CurrencyManager
Dim ketemu As Boolean
Public m As Integer
- Label Page/Halaman
Private Sub posisi()
Me.Label9.Text = cm.Position + 1 & " Page " & cm.Count
End Sub
- Membuka Database
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
cn.Open()
ds = New DataSet("Barang")
Dim cb As New OleDbCommandBuilder(da)
da.Fill(dt)
cm = CType(Me.BindingContext(dt), CurrencyManager)
cm.Position = 0
tampil()
Me.DataGridView1.DataSource = dt
cn.Close()
posisi()
End Sub
End Class
- Tombol Go Top
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button5.Click
cm.Position = 0
tampil()
posisi()
End Sub
- Tombol Back
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button6.Click
cm.Position = cm.Position - 1
tampil()
posisi()
End Sub
- Tombol Next
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button8.Click
cm.Position = cm.Position + 1
tampil()
posisi()
End Sub
- Tombol Go Bottom
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button7.Click
cm.Position = cm.Count
tampil()
posisi()
End Sub
- Button Cari/Browse
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
cari()
Dim Jawab As Integer
If ketemu = True Then
tampil()
Else
Jawab = MsgBox("Data tidak ada", MsgBoxStyle.OkOnly +
MsgBoxStyle.Exclamation, "Pesan")
Me.TextBox2.Text = ""
Me.TextBox3.Text = ""
Me.TextBox4.Text = ""
Me.ComboBox1.Text = "Pilih"
Me.ComboBox2.Text = "Pilih"
End If
End Sub
- Button Keluar
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button4.Click
Dim Keluar As Integer
Keluar = MessageBox.Show("Anda yakin ingin keluar?", "Pesan",
MessageBoxButtons.YesNo, MessageBoxIcon.Question)
If Keluar = MsgBoxResult.Yes Then
Me.Close()
End If
End Sub
- Button Simpan/Save
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
cari()
If ketemu = False Then
cm.AddNew()
cm.Position = cm.Count
End If
dt.Rows(cm.Position).Item("kode") = TextBox1.Text
dt.Rows(cm.Position).Item("nama") = TextBox2.Text
dt.Rows(cm.Position).Item("jenis") = ComboBox1.Text
dt.Rows(cm.Position).Item("jumlah") = TextBox3.Text
dt.Rows(cm.Position).Item("satuan") = ComboBox2.Text
dt.Rows(cm.Position).Item("harga") = TextBox4.Text
da.Update(dt)
Me.TextBox1.Text = ""
Me.TextBox2.Text = ""
Me.TextBox3.Text = ""
Me.TextBox4.Text = ""
Me.ComboBox1.Text = "Pilih"
Me.ComboBox2.Text = "Pilih"
- Button Hapus/Delete
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim jawab As Integer
cari()
If ketemu = True Then
jawab = MsgBox("Data Sudah Ada, Mau Dihapus?", MsgBoxStyle.YesNo +
MsgBoxStyle.Exclamation, "Pesan")
If jawab = DialogResult.Yes Then
cm.RemoveAt(cm.Position)
da.Update(dt)
End If
End If
Me.TextBox1.Text = ""
Me.TextBox2.Text = ""
Me.TextBox3.Text = ""
Me.TextBox4.Text = ""
Me.ComboBox1.Text = "Pilih"
Me.ComboBox2.Text = "Pilih"
'------- Mengarahkan Kursor ke TextBox1
Me.TextBox1.Focus()
End Sub