Kebetulan di salah satu Komunitas Programer VB di FB menawarkan DataBase Gratis tapi hanya untuk Pembelajaran
FB nya : klik sini
atau kunjungi Komunitas ini :
Untuk koneksi Data Base nya saya buat Module :
Imports MySql.Data.MySqlClient
Imports System.Data
Module modulku
Dim ConString = "server=dikoding.cloudapp.net;Port=24555; User ID=user_kami; password=123; database=jomblo"
Public db As New MySqlConnection(ConString)
Public Sub konek()
Try
tutupDB()
db.Open()
MsgBox("Koneksi DataBase berhasil dilakukan")
Catch ex As MySqlException
MsgBox(ex.Message)
MsgBox("Koneksi tidak berhasil dilakukan")
End Try
End Sub
Public Sub tutupDB()
If db.State = ConnectionState.Open Then
db.Close()
End If
End Sub
End Module
Coding berikutnya :
Imports MySql.Data.MySqlClient
Public Class Form1
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
tutupDB()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
konek()
DisplayData()
End Sub
Private Sub DisplayData()
Dim da As New MySqlDataAdapter("SELECT * FROM daftar_jomblo", db)
Dim dt As New DataTable
da.Fill(dt)
dgv.DataSource = dt
'percantik Grid
dgv.GridColor = Color.Cyan
dgv.DefaultCellStyle.ForeColor = Color.Black
dgv.RowsDefaultCellStyle.BackColor = Color.PaleGreen
dgv.AlternatingRowsDefaultCellStyle.BackColor = Color.PapayaWhip
dgv.GridColor = Color.Silver
'merubah ukuran dari kolom
dgv.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells
End Sub
Private Sub btnrefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnrefresh.Click
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
konek()
Dim cmd As New MySqlCommand("insert into daftar_jomblo(Idjomblo, Nama_jomblo, No_hp) values('" & txtid.Text & "','" & txtnama.Text & "','" & txthp.Text & "')", db)
cmd.ExecuteNonQuery()
DisplayData()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class
Hasilnya :
Selamat Otak Atik
jadi cara koneksi nya hanya perlu taruh nama server dan port sesuai dgn database hosting nya ya, makasih info nya gan.
BalasHapustapi nama database nya ngenes bgt gan :v
Halo saya ingin tanya, saya pemula vb.net, itu domain name dicoding.cloudapl.net mksdnya apa ya?? Dan port tsb dri port apa ya? Maaf saya newbie dan blm tau apa2:)
BalasHapus