untuk mendesain form pelanggan yang kita butuhkan adalah
tools yang dibutukan :
1. Groupbox sebanyak 2 buah
2. label sebanyak 6 buah
3. textbox sebanyak 5 buah
4. datagrid sebanyak1 buah
5. Serta sebuah database yang telah pernah disimpan dan menambahkan table tblPelanggan dengan isi
*Kode_Pelanggan
*Nama_Pelanggan
*Alamat
*Telepon
*Kota
6. Button sebanyak4 buah
7. icon untuk tombol sebanyak 3
kemudian ubah nama tool tersebut sesuai di gambar
untuk Source code sebagai berikut :Imports System.Data.OleDb
Public Class frmPelanggan
Private Conns As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & System.AppDomain.CurrentDomain.BaseDirectory & "\apotek.mdb;Persist Security Info=false"
Private Conn As New OleDbConnection
Public Function akses() As OleDbConnection
Dim conect As New OleDbConnection(Conns)
conect.Open()
Return conect
End Function
Private Sub frmPelanggan_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Conn.ConnectionString = Conns
Dim grid As OleDbDataAdapter
grid = New OleDbDataAdapter("select * from tblPelanggan", Conn)
Dim ds As DataSet
ds = New DataSet
grid.Fill(ds, "tblPelanggan")
DataGridView1.DataSource = ds.Tables("tblPelanggan")
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Cmd As New OleDbCommand
Dim conns As New OleDbConnection
Conn.Open()
Cmd.CommandText = "INSERT INTO tblPelanggan VALUES ('" & TextBox1.Text & "' ,'" & TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & TextBox5.Text & "')"
Cmd.Connection = Conn
Cmd.ExecuteNonQuery()
Conn.Close()
Dim grid As OleDbDataAdapter
grid = New OleDbDataAdapter("select * from tblPelanggan", Conn)
Dim ds As DataSet
ds = New DataSet
grid.Fill(ds, "tblPelanggan")
DataGridView1.DataSource = ds.Tables("tblPelanggan")
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Beranda.Show()
Me.Hide()
End Sub
Private Sub print_Click(sender As Object, e As EventArgs) Handles print.Click
End Sub
End Class
debug dan jalankan aplikasi. kemudian isi form untuk mengisi datagridview
Tidak ada komentar:
Posting Komentar