INPUT Database MySQL VB 2010
Imports System.Data.Odbc
Public Class Form1
Dim Conn As OdbcConnection
Dim da As OdbcDataAdapter
Dim ds As DataSet
Dim str As String
Dim CMD As OdbcCommand
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Call KondisiAwal()
End Sub
Sub Koneksi()
str = "Driver={MySQL ODBC 5.3 ANSI
Driver};database=DBperpustakaan;server=localhost;uid=root"
Conn = New OdbcConnection(str)
If Conn.State = ConnectionState.Closed Then
Conn.Open()
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 TextBox3.Text = "" Or
TextBox4.Text = "" Then
MsgBox("Data belum lengkap, Pastikan nomor anggota 6 Digit dan Semua
form terisi")
Exit Sub
Else
Call Koneksi()
Dim simpan As String = "insert into anggota values ('" &
TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "','" &
TextBox4.Text & "')"
CMD = New OdbcCommand(simpan, Conn)
CMD.ExecuteNonQuery()
MsgBox("Data berhasil di Input", MsgBoxStyle.Information,
"Information")
Call KondisiAwal()
End If
End Sub
Sub KondisiAwal()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
Me.Text = "www.belajarvb.com"
Koneksi()
da = New OdbcDataAdapter("Select * from anggota ", Conn)
ds = New DataSet
ds.Clear()
da.Fill(ds, " anggota ")
DataGridView1.DataSource = (ds.Tables("anggota"))
End Sub
End Class
Imports System.Data.Odbc
Public Class Form1Petugas
Dim Conn As OdbcConnection
Dim
Dim
Dim
Dim
da As OdbcDataAdapter
ds As DataSet
str As String
CMD As OdbcCommand
Private Sub FormPetugas_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles MyBase.Load
Call KondisiAwal()
End Sub
Sub Koneksi()
str = "Driver={MySQL ODBC 5.3 ANSI
Driver};database=Dbperpus;server=localhost;uid=root"
Conn = New OdbcConnection(str)
If Conn.State = ConnectionState.Closed Then
Conn.Open()
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 TextBox3.Text = "" Or TextBox4.Text = "" Then
MsgBox("Data belum lengkap, Pastikan kode petugas 6 Digit dan Semua form terisi")
Exit Sub
Else
Call Koneksi()
Dim simpan As String = "insert into petugas values ('" & TextBox1.Text & "','" &
TextBox2.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "')"
CMD = New OdbcCommand(simpan, Conn)
CMD.ExecuteNonQuery()
MsgBox("Data berhasil di Input", MsgBoxStyle.Information, "Information")
Call KondisiAwal()
End If
End Sub
Sub KondisiAwal()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
Koneksi()
da = New OdbcDataAdapter("Select * from petugas ", Conn)
ds = New DataSet
ds.Clear()
da.Fill(ds, " petugas ")
DataGridView1.DataSource = (ds.Tables("petugas"))
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button4.Click
Me.Close()
End Sub
End Class