0% found this document useful (0 votes)
35 views

Input Database Mysql VB 2010

This document contains code for a Visual Basic 2010 application that connects to a MySQL database. It includes code to connect to the database, insert data into tables, and display data in a datagrid. The code defines classes for forms that allow inputting and viewing data for library members and employees tables. Methods are included to connect to the database, insert records, clear form fields, and load data into the datagrid for display.

Uploaded by

Egi Ginanjar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Input Database Mysql VB 2010

This document contains code for a Visual Basic 2010 application that connects to a MySQL database. It includes code to connect to the database, insert data into tables, and display data in a datagrid. The code defines classes for forms that allow inputting and viewing data for library members and employees tables. Methods are included to connect to the database, insert records, clear form fields, and load data into the datagrid for display.

Uploaded by

Egi Ginanjar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

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

You might also like