Form1 Odbcconnection Odbccommand Dataset Odbcdataadapter Odbcdatareader

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Imports System.Data.

Odbc
Public Class Form1
Dim CONN As OdbcConnection
Dim CMD As OdbcCommand
Dim DS As New DataSet
Dim DA As OdbcDataAdapter
Dim RD As OdbcDataReader
Dim LokasiData As String
Sub Koneksi()
LokasiData = "Driver={MySQL ODBC 3.51
Driver};Database=data_inventaris01;server=localhost;uid=root"
CONN = New OdbcConnection(LokasiData)
If CONN.State = ConnectionState.Closed Then
CONN.Open()
End If
End Sub
Sub TampilGrid()
Call Koneksi()
DA = New OdbcDataAdapter("select * From tbl_barang ", CONN)
DS = New DataSet
DA.Fill(DS, "tbl_barang")
DataGridView1.DataSource = DS.Tables("tbl_barang")
DataGridView1.ReadOnly = True
End Sub
Sub KosongkanData()
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""

End Sub
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Me.Close()
End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


Call TampilGrid()
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click


menubantuan.Show()
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click


If TextBox3.Text = "" Then
MsgBox("Silahkan Pilih Data yang akan di hapus dengan Masukan Nama barang
yang akan dihapus")
Else
If MessageBox.Show("Yakin akan dihapus..?", "", MessageBoxButtons.YesNo) =
Windows.Forms.DialogResult.Yes Then
Call Koneksi()
Dim hapus As String = "delete From tbl_barang where nama_barang='" &
TextBox3.Text & "'"
CMD = New OdbcCommand(hapus, CONN)
CMD.ExecuteNonQuery()
Call TampilGrid()
Call KosongkanData()
End If
End If
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click


Call Koneksi()
Dim simpan As String = "insert into tbl_barang values ('" & TextBox3.Text & "','"
& TextBox4.Text & "','" & TextBox5.Text & "','" & TextBox2.Text & "')"
CMD = New OdbcCommand(simpan, CONN)
CMD.ExecuteNonQuery()
MsgBox("Input data berhasil")
Call TampilGrid()
Call KosongkanData()
End Sub

Private Sub Panel1_Paint(sender As Object, e As PaintEventArgs) Handles Panel1.Paint

End Sub

Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click


Dim conn As New MySql.Data.MySqlClient.MySqlConnection
Dim koneksiku As String

koneksiku = "server=localhost;uid=root;pwd='';database='data_inventaris01'"
Try
conn.ConnectionString = koneksiku
conn.Open()
MsgBox("koneksi berhasil", MsgBoxStyle.Information, "informasi")

Catch ex As Exception
MessageBox.Show(ex.Message)
End Try

End Sub

End Class

You might also like