VB .Net 2005 - DB MySQL Connection

In this tutorial we will share about VB .Net 2005 - MySQL Connection. Before following this tutorial, please make sure you already have Xampp application and install odbc (MySQL ODBC 3.51) in your computer.

#1
Create Database in MySQL (Xampp) with name of database = mydb
Create table = TBL_PRODUCT
Fill sample data in TBL_PRODUCT
#2
Open your VB 2005 Application
Design form1 like below picture :
Just add "Datagridview1" in Form1

Fill below code at Form1
Imports System.Data.Odbc
Public Class Form1
    Dim Conn As OdbcConnection
    Dim da As OdbcDataAdapter
    Dim ds As DataSet
    Dim str As String
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) _
       Handles MyBase.Load
        Me.Text = "www.belajarvb.com"
        Koneksi()
        da = New OdbcDataAdapter("Select * from TBL_PRODUCT", Conn)
        ds = New DataSet
        ds.Clear()
        da.Fill(ds, "TBL_PRODUCT")
        DataGridView1.DataSource = (ds.Tables("TBL_PRODUCT"))
    End Sub
    Sub Koneksi()
        str = "Driver={MySQL ODBC 3.51 Driver};database=mydb;server=localhost;uid=root"
        Conn = New OdbcConnection(Str)
        If Conn.State = ConnectionState.Closed Then
            Conn.Open()
        End If
    End Sub
End Class

Please run your project
You can click here to download project / source code above

Subscribe to receive free email updates:

0 Response to "VB .Net 2005 - DB MySQL Connection"

Post a Comment