Koneksi ke Database Ms.Access dengan VB.net

by mimmafachranie

Applikasi ini untuk mengkoneksikan database dari ms. access ke vb.net dan ditampilkan dengan lebih simple. Hal pertama-tama membuat database di vb.net. setelah itu, konesikan dengan vb.net pada server explorer. beginilah tampilannya

Pertama kita Log In terlebih dahulu dengan cara memasukan username dan password dengan benar

Step1

 

 

Jika Password salah, maka tampilannya seperti ini :

Step2

 

Jika Password benar, maka langsung masuk ke mdiParrent-nya :

Step3

 

Pilih Open, lalu Persediaan maka tampilannya seperti ini :

Step4

 

Ada button Search, yang berguna untuk mencari data pada kolum :

Step5

 

Form Penjualan :

Step6

Tombol Print gunanya untuk menampilkan laporan :

Step7

 

Koding :

Form Persediaan :

Imports System.Data.OleDb
Public Class Form1
Dim str As String
Dim kon As New OleDbConnection
Dim da As New OleDbDataAdapter
Dim ds As New DataSet
Dim comm As New OleDbCommand

Sub konek()

str = “Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\ABDUL CHOIR\Documents\Tugas VB.accdb”
kon = New OleDbConnection(str)

End Sub

Sub isiGrid()

da = New OleDbDataAdapter(“Select * from TPersediaan”, kon)
ds = New DataSet
da.Fill(ds, “TPersediaan”)
DataGridView1.DataSource = (ds.Tables(“TPersediaan”))

End Sub

Private Sub FormUtama_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call konek()
Call isiGrid()
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x = InputBox(“Masukkan Nama Barang yang dicari?”, “CariData”)
comm.Connection = kon
comm.CommandType = CommandType.Text
comm.CommandText = “Select * from TPersediaan where Nama Barang = ‘” & Trim(x) & “‘”

Dim DR = comm.ExecuteReader
DR.Read()

If DR.HasRows = True Then
MsgBox(“Data ada”)

Else
MsgBox(“Data tidak ada”)

End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
MDIParent1.Show()

End Sub
End Class

Form Log In :

Public Class Form2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If (TextBox2.Text = “vokasi”) Then
Me.Hide()
MDIParent1.Show()
Else
MessageBox.Show(“Password Salah”)

End If
End Sub
End Class

 

Form Penjualan :

ublic Class Form3

Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
‘TODO: This line of code loads data into the ‘DataSet1.TPenjualan’ table. You can move, or remove it, as needed.
Me.TPenjualanTableAdapter.Fill(Me.DataSet1.TPenjualan)

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Form4.Show()

End Sub

Private Sub BindingNavigatorMoveNextItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorMoveNextItem.Click
TPenjualanBindingSource.MoveNext()

End Sub

Private Sub BindingNavigatorAddNewItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BindingNavigatorAddNewItem.Click

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
MDIParent1.Show()

End Sub
End Class

 

 

*Notes :

Saat Membuat Binding Navigator, jangan lupa memasukan pada properties binding source-nya diisi binding source yang ingin diisi :

Notes

Sekian.

About these ads