To make connection from VB.NET into MySQL we must do the following thing :
1. Download MySQL database engine from http://dev.mysql.com/downloads/
2. Install the MySQL
3. After that, you must download the connector from VB.NET into MySQL from www.mysql.com/products/connector/net
4. To use the connector, just Import the reference of MySQL DotNet Connector from Project->Add Reference
5. Make one module to do a connection into MySQL
Imports MySql.Data.MySqlClient
Module Connect
Public conn As New MySqlConnection
Public Sub ConnectDatabase()
Try
If conn.State = ConnectionState.Closed Then
conn.ConnectionString = "DATABASE=" & your database &";" _
& "SERVER=" & your host & ";user id=" & your username _
& ";password=" & your password & ";port=" & Your MySQL Port (3306) & ";charset=utf8"
conn.Open()
End If
Catch myerror As Exception
MsgBox("Connection Error")
End
End Try
End Sub
Public Sub DisconnectDatabase()
Try
conn.Close()
Catch myerror As MySql.Data.MySqlClient.MySqlException
End Try
End Sub
End Module
6. To connect to MySQL, just call the ConnectDatabase() from your form_load event
No comments:
Post a Comment