We can do this many ways,
1) In the MySQL site there is a library to connect to MySQL.
http://www.mysql.com/products/connector/
Download and install this library. Infact we need only the MySql.Data.dll added as a reference to the project. Then we can work like rest like the ado.net providers with MySQL Connection, MySQLCommand, MySQLDataAdapter and MySQLDataReader
Imports MySql.Data.MySqlClient
Public Sub LoadMySQLDB()
Dim myConnection As MySqlConnection
Dim myDataAdapter As MySqlDataAdapter
Dim myDataSet As DataSet
Dim strSQL As String
myConnection = New MySqlConnection("server=localhost; user id=user1; password=password; database=mydatabase; pooling=false;")
strSQL = "SELECT * FROM mytable;"
myDataAdapter = New MySqlDataAdapter(strSQL, myConnection)
myDataSet = New DataSet()
myDataAdapter.Fill(myDataSet, "mytable")
MySQLDataGrid.DataSource = myDataSet
MySQLDataGrid.DataBind()
End Sub
2) Using OLEDB we can connect to MySQL
3) Using ODBC also we can connect to MySQL.
No comments:
Post a Comment