sedang dapet tantangan nie,, connect MySQL dengan VB.Net 2008 sampai di bela-belain ninggalin kerjaan dari Jam 10.00-14.00 #kox jadi curhat ea,,, hehe langsung saja ini dia penampakan awalnya
#STEP 1 (Otak Masih Seger)
Sebelumnya kamu harus download dulu connector MySQL untuk VB.Net disini
Buat Project Baru lalu Klik
Project>>ad Preference>>MySql.Data
#STEP 2 (Tangan Mulai Pegel)
Design Form Seperti ini
KomponenNya:
*DataGridview
*Label
( lblMsg = soedirman_hmti, Label1=No.id, Label2=Nama, Label3=Usia)
*Button
(AddRecords=AddRecords, UpdateRecords=UpdateRecords, DeleteRecords=DeleteRecords, DisplayRecords=DisplayRecords)
*TextBox
txtUserRegId="", txtUserName="", txtAge="",
#STEP 3 (Otak Mulai Ngebul)
Nie ane kasih GRATISS!! Jangan Cuma COPAS Tapi Pelajari ea....perhatiin Warna Biru untuk CopasNya
//soedirman-hmti.blogspot.com
Imports MySql.Data.MySqlClient
Public Class Form1
Private Sub DisplayRecords_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DisplayRecords.Click
Dim con As MySqlConnection = New MySqlConnection("Data Source=localhost;Database=test;User ID=root;Password=;")
Dim sql As MySqlCommand = New MySqlCommand("SELECT * FROM userreg", con)
Dim ds As DataSet = New DataSet()
Dim DataAdapter1 As MySqlDataAdapter = New MySqlDataAdapter()
con.Open()
DataAdapter1.SelectCommand = sql
DataAdapter1.Fill(ds, "Product")
DataGridView1.DataSource = ds
DataGridView1.DataMember = "Product"
con.Close()
End Sub
Private Sub AddRecords_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddRecords.Click
Dim Query As String
'Query = "INSERT INTO userreg"
Dim con As MySqlConnection = New MySqlConnection("Data Source=localhost;Database=test;User ID=root;Password=;")
'Dim sql As MySqlCommand = New MySqlCommand(Query, con)
Query = "INSERT INTO userreg(idUserReg,UserName, Age)VALUES("
Query = Query + txtUserRegId.Text + ",'" + txtUserName.Text + "'," + txtAge.Text + ")"
con.Open()
Dim cmd As MySqlCommand = New MySqlCommand(Query, con)
Dim i As Integer = cmd.ExecuteNonQuery()
If (i > 0) Then
lblMsg.Text = "Record is Successfully Inserted"
Else
lblMsg.Text = "Record is not Inserted"
End If
con.Close()
End Sub
Private Sub UpdateRecords_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpdateRecords.Click
Dim Query As String
Dim con As MySqlConnection = New MySqlConnection("Data Source=localhost;Database=test;User ID=root;Password=;")
con.Open()
Query = "UPDATE userreg SET UserName ='" + txtUserName.Text + "',"
Query = Query + "Age = " + txtAge.Text
Query = Query + " WHERE idUserReg = " + txtUserRegId.Text
Dim cmd As MySqlCommand = New MySqlCommand(Query, con)
MsgBox(Query)
Dim i As Integer = cmd.ExecuteNonQuery()
If (i > 0) Then
lblMsg.Text = "Record is Successfully Updated"
Else
lblMsg.Text = "Record is not Updated"
End If
con.Close()
End Sub
Private Sub DeleteRecords_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DeleteRecords.Click
Dim Query As String
Dim con As MySqlConnection = New MySqlConnection("Data Source=localhost;Database=test;User ID=root;Password=;")
con.Open()
Query = "Delete FROM userreg WHERE idUserReg =" + txtUserRegId.Text
Dim cmd As MySqlCommand = New MySqlCommand(Query, con)
MsgBox(Query)
Dim i As Integer = cmd.ExecuteNonQuery()
If (i > 0) Then
lblMsg.Text = "Record is Successfully Deleted"
Else
lblMsg.Text = "Record is not Deleted"
End If
con.Close()
End Sub
End Class
#STEP 4 (Pendinginan)
Jangan Lupa Buat Dulu DataBaseNya biar mudah dengan XAMPP j
#STEP 5 (PUUUASSSSS)
RUN!! dan Lihat PenampakanNYA
WARNING SYNTAX
Dim con As MySqlConnection = New MySqlConnection("Data Source=localhost;Database=test;User ID=root;Password=;")
// Punya saya Xampp tanpa Password kalau kamu ada Password Tulis adja Password=dirman;
Recomended This ea,,
dan jangan lupa Tampilkan Link refrensi jika mau Copas
ty gana, gw coba pelajari, lagi belajar ulang dari vb 6 menjadi vb net. jadi butuh bantuan lihat perubahan aja gan. ty gan
BalasHapusMantap mas bray
BalasHapusMantap gan.....
BalasHapusThank You(Y)
#sambil Ngakak ane baca nya :D
kang klo pake odbc untuk sintax updatenya gmna ya kang ane pake xampp untuk dbnya kang
BalasHapusowh ya klo minsalkan di formnya cuman mau ambil beberapa field ajj dri table database caranya gmna ya kang?? bener udah butek ni pngen meledak otak mana saya tinggal di hutan gak ada tmn laen tuk bertanya kang.heehee
BalasHapus