Vbnet1.docx

  • Uploaded by: Muhammad Zainudin
  • 0
  • 0
  • December 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Vbnet1.docx as PDF for free.

More details

  • Words: 605
  • Pages: 5
Module 'access Imports System.Data.OleDb Imports System.Data.SqlClient 'sqrserver Imports System.Data.Odbc 'mysql

Module Module1 Public Public Public Public Public Public Public

conn As OleDbConnection da As OleDbDataAdapter ds As DataSet cmd As OleDbCommand dr As OleDbDataReader adaptor As OleDbDataAdapter read As OleDbDataReader

Public Sub Koneksi() conn = New OleDbConnection("provider=microsoft.jet.OleDb.4.0;data source=TI18A.mdb") conn.Open() End Sub End Module

Syntax form Imports System.Data.OleDb 'wajib Public Class Customer Dim Pilihan As String 'untuk mengkosongkan yang sudah tersimpan pada textbox Sub kosongkan() TextBox1.Clear() TextBox2.Clear() RadioButton1.Checked = False RadioButton2.Checked = False TextBox1.Focus() End Sub 'untuk menampil data baru yang sudah tersimpan pada textbox Sub DataBaru() TextBox2.Clear() RadioButton1.Checked = False RadioButton2.Checked = False TextBox2.Focus() End Sub Sub Ketemu() On Error Resume Next TextBox2.Text = dr.Item("Nama_Customer") If dr.Item("Jenis_Usaha") = "Barang" Then RadioButton1.Checked = True ElseIf dr.Item("Jenis_Usaha") = "Jasa" Then RadioButton2.Checked = True End If TextBox2.Focus() End Sub Sub TampilGrid() da = New OleDbDataAdapter("Select * from tblCustomer", conn) ds = New DataSet da.Fill(ds) DGV.DataSource = ds.Tables(0) DGV.ReadOnly = True End Sub Sub CariKode() cmd = New OleDbCommand("Select * from tblCustomer where Kode_Customer='" & TextBox1.Text & "'", conn) dr = cmd.ExecuteReader dr.Read() End Sub Private Sub Customer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Call Koneksi() Call kosongkan() Call TampilGrid() End Sub

Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown 'If e.KeyCode = Keys.Enter Then ' Call CariKode() ' If dr.HasRows() Then ' Call Ketemu() ' Else ' Call DataBaru() ' End If 'End If End Sub Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress TextBox1.MaxLength = 5 If e.KeyChar = Chr(13) Then Call CariKode() If dr.HasRows() Then 'jika datanya ditemukan Call Ketemu() Else Call DataBaru() End If End If End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click If TextBox1.Text = "" Or TextBox2.Text = "" Or RadioButton1.Checked = False And RadioButton2.Checked = False Then MsgBox("data belum lengkap") Exit Sub Else End If Try If RadioButton1.Checked = True Then Pilihan = RadioButton1.Text 'Barang() ElseIf RadioButton2.Checked = True Then Pilihan = RadioButton2.Text 'Jasa End If Call CariKode() If Not dr.HasRows Then Dim simpan As String = "insert Into tblCustomer values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & Pilihan & "')" cmd = New OleDbCommand(simpan, conn) cmd.ExecuteNonQuery() Else 'jika tidak ditemukan Dim edit As String = "update tblCustomer set Nama_Customer='" & TextBox2.Text & "',Jenis_Usaha='" & Pilihan & "' where Kode_Customer='" & TextBox1.Text & "'" cmd = New OleDbCommand(edit, conn)

cmd.ExecuteNonQuery() End If Call kosongkan() Call TampilGrid() Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click If TextBox1.Text = "" Then MsgBox("Kode harus diisi") TextBox1.Focus() Exit Sub End If Call CariKode() If Not dr.HasRows Then MsgBox("Kode Customer tidak terdaftar") TextBox1.Focus() Exit Sub End If If MessageBox.Show("Apakah Anda Yakin?", "", MessageBoxButtons.YesNo) = Windows.Forms.DialogResult.Yes Then Dim hapus As String = "delete * From tblCustomer where Kode_Customer='" & TextBox1.Text & "'" cmd = New OleDbCommand(hapus, conn) cmd.ExecuteNonQuery() Call kosongkan() Call TampilGrid() Else Call kosongkan() End If End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Call kosongkan() End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click Me.Close() End Sub

Private Sub DGV_CellMouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DGV.CellMouseClick On Error Resume Next TextBox1.Text = DGV.Rows(e.RowIndex).Cells(0).Value Call CariKode() If dr.HasRows Then Call Ketemu()

End If End Sub Private Sub TextBox6_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox6.TextChanged Call Koneksi() da = New OleDbDataAdapter("select * from tblCustomer where Nama_Customer like '%" & TextBox6.Text & "%'", conn) ds = New DataSet da.Fill(ds) DGV.DataSource = ds.Tables(0) DGV.ReadOnly = True End Sub End Class

More Documents from "Muhammad Zainudin"

Vbnet1.docx
December 2019 32
Tugas Bu Sugi.docx
December 2019 33
Beban_dan_perletakan.docx
December 2019 25
Tugas Bu Sugi.docx
December 2019 39
Dunia
May 2020 34
Pemimpin
May 2020 34