Posted by: Taong Grasa | May 16, 2008

Connecting VB.net 2005 to a MYSQL Database

As i started with my new project.  I choose vb.net 2005 and PHP to write my Frontend applications and MySQL for my Backend.  There is no problem connecting my PHP program to a MySQL database… The problem is how can I connect my VB.net program to a MySQL database??? Connecting a VB.net program to a Microsoft SQL Server and to a Oracle is a walk in the park.  After a couple of Googling and some sweat & blood hehehe… I come up with this solutions…..

First download and install a MySQL Connector for .NET here

Then in VB.NET IDE go to Project > Add Reference… In the .NET Tab Add the MySQL.Data Reference and click OK

Use this code to Open a Database Connection:

Imports MySql.Data.MySqlClient

Public Conn As MySqlConnection

Sub OpenDatabase()

Conn = New MySqlConnection()

Conn.ConnectionString = “server=localhost; Port=3306; user id=USER; password=PASSWORD; database=MyDatabase”

End Sub


Responses

  1. How do I install the MySQL Connector?

    • just download and install the setup then instantiate first before you use it to your program =)

  2. Have you tried the 6.0.4 connector? I’m having an error installing it, kaso kelangan talaga kasi it has relevant improvements on speedup. Any ideas on this?

  3. how to add data in the database using the forms?


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: