Hallo selamat siang semua.. ketemu saya lagi nih disini hehehe kali ini saya akan membahas mengenai database dan data bindings dalam visual basic (dot) net.Ini adalah materi VB(dot)Net latihan saya di kampus.Sebenarnya cukup sulit untuk menyatukannya antara form data set, data adapter, data source, dan data connection.Saya rasa semua sudah bisa dasarnya dalam pembuatan form-form, makan saya tidak akan menjelaskan lagi.Okeyy langsung saja mari kita simak codingan berikut ini dengan teliti dan cermat..
Public Class Form1
Dim WithEvents objcurr As CurrencyManager
Dim objDateView As DataView
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the 'BukuDataSet.Buku' table. You can move, or remove it, as needed.
Me.BukuTableAdapter.Fill(Me.BukuDataSet.Buku)
'Me.OleDbDataAdapter1.Fill(Me.BukuDataSet.Buku)
objDateView = New DataView(BukuDataSet.Tables("buku"))
objcurr = CType(Me.BindingContext(objDateView), CurrencyManager)
DataGridView1.DataSource = objDateView
DataGridView1.Refresh()
End Sub
Private Sub btnsave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnsave.Click
BukuDataSet.Buku.AddBukuRow(txt_kd_buku.Text, txtnmbk.Text, txtpngrng.Text, txthrg.Text)
OleDbDataAdapter1.Update(BukuDataSet.Buku)
objDateView = New DataView(BukuDataSet.Tables("buku"))
objcurr = CType(Me.BindingContext(objDateView), CurrencyManager)
DataGridView1.DataSource = objDateView
DataGridView1.Refresh()
Btnupdate.Enabled = True
Btnadd.Enabled = True
Btnsave.Enabled = False
End Sub
Private Sub btnexit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_exit.Click
End
End Sub
Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnadd.Click
bersihkan()
txt_kd_buku.Text = ""
txtnmbk.Text = ""
txtpngrng.Text = ""
txthrg.Text = ""
Btnsave.Enabled = True
Btnadd.Enabled = False
Btnupdate.Enabled = False
End Sub
Private Sub btnupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnupdate.Click
Dim pos As Integer
bersihkan()
BukuDataSet.Buku(Me.BindingContext(BukuDataSet, "buku").Position).EndEdit()
'Me.BukuDataSet.Buku.FindBykd_buku(Me.txt_kd_buku.Text).nm_buku = Me.txtnmbk.Text
'Me.BukuDataSet.Buku.FindBykd_buku(Me.txt_kd_buku.Text).nm_pengarang = Me.txtpngrng.Text
'Me.BukuDataSet.Buku.FindBykd_buku(Me.txt_kd_buku.Text).harga = Me.txthrg.Text
OleDbDataAdapter1.Update(BukuDataSet.Buku)
objcurr.Position = pos
OleDbConnection1 = Nothing
Btnadd.Enabled = True
End Sub
Private Sub btndelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
'Me.BukuDataSet.Buku.FindBykd_buku(Me.txt_kd_buku.Text).Delete()
OleDbDataAdapter1.Update(BukuDataSet.Buku)
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
objcurr.Position += 1
End Sub
Private Sub tampil()
Me.txt_kd_buku.Text = New DataView(BukuDataSet.Tables("buku")).Item(objcurr.Position).Item("kd_buku")
Me.Txtpngrng.Text = New DataView(BukuDataSet.Tables("buku")).Item(objcurr.Position).Item("nm_pengarang")
Me.Txtnmbk.Text = New DataView(BukuDataSet.Tables("buku")).Item(objcurr.Position).Item("nm_buku")
Me.Txthrg.Text = New DataView(BukuDataSet.Tables("buku")).Item(objcurr.Position).Item("harga")
End Sub
Private Sub objCurrencyManager_PositionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles objcurr.PositionChanged
tampil()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
objcurr.Position -= 0
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
objcurr.Position -= 1
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
objcurr.Position = objcurr.Count()
End Sub
Private Sub bersihkan()
txt_kd_buku.DataBindings.Clear()
txtnmbk.DataBindings.Clear()
txtpngrng.DataBindings.Clear()
txthrg.DataBindings.Clear()
End Sub
End Class
Bisa dilihat diatas, itu contoh membuat database pada toko buku.Saya merancangnya dengan sedikit panduan dari modul dosen kampus saya.Untuk lebih jelasnya bisa kalian coba dirumah atau di kampus dengan VB sendiri.Sekiranya cukup jelas sampai disini, kurang lebihnya mohon maaf.Selamat membaca, semoga dapat menambah ilmu anda.Salam mahasiswa!! :)
Follow me: @deaprantika ;)
Yuk Merapat Best Betting Online Hanya Di AREATOTO
BalasHapusDalam 1 Userid Dapat Bermain Semua Permainan
Yang Ada :
TARUHAN BOLA - LIVE CASINO - SABUNG AYAM - TOGEL ONLINE ( Tanpa Batas Invest )
Sekedar Nonton Bola ,
Jika Tidak Pasang Taruhan , Mana Seru , Pasangkan Taruhan Anda Di areatoto
Minimal Deposit Rp 20.000 Dan Withdraw Rp.50.000
Proses Deposit Dan Withdraw ( EXPRES ) Super Cepat
Anda Akan Di Layani Dengan Customer Service Yang Ramah
Website Online 24Jam/Setiap Hariny