Konsep database online sebenarnya sama saja dengan database localhost, bedanya hanya pada server dan penambahan isian port pada connection string. Kemudian database hosting ini adalah database yang dishare oleh programmer yang mempunyai situs dikoding .
Database sewaktu-waktu dapat berubah atau tidak berfungsi lagi, tergantung dari pemiliki situr. Hosting ini bersifat gratis atau tanpa dipungut biaya apapun.Code Program :
Imports MySql
Imports MySql.Data
Imports MySql.Data.MySqlClient
Public Class Form1
Dim conn As New MySqlConnection
Dim cmd As MySqlCommand
Dim str As String = ""
Dim Readersql As MySqlDataReader
Private Sub cmdConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdConnect.Click
If conn.State = 1 Then conn.Close()
conn.ConnectionString = "server=" & txtServer.Text & ";port=" & txtPort.Text & _
";uid=" & txtUserName.Text & ";password=" & txtPassword.Text & ";database=test"
Try
conn.Open()
MsgBox("Koneksi Berhasil")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub cmdShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdShow.Click
Dim i As Integer = 0
If conn.State = ConnectionState.Open Then
str = "show databases"
cmd = New MySqlCommand(str, conn)
Readersql = cmd.ExecuteReader
lv.Items.Clear()
While Readersql.Read
i += 1
Dim itemm As New ListViewItem
itemm.Text = i
itemm.SubItems.Add(Readersql("Database"))
lv.Items.Add(itemm)
End While
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
lv.View = View.Details
lv.GridLines = True
lv.Columns.Add("No.")
lv.Columns.Add("Nama Database")
End Sub
Private Sub cmdBuat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBuat.Click
If conn.State = ConnectionState.Open Then
str = "Create database " & txtDbName.Text
cmd = New MySqlCommand(str, conn)
Try
cmd.ExecuteNonQuery()
MsgBox("Database Terbuat, Silahkan Klik Show Database")
Catch ex As Exception
MsgBox(ex.Message)
End Try
End If
End Sub
End Class
Post a Comment