views:

363

answers:

1

Can Anybody tell me how to connect ASP to MySQL database.. I have already install MySQL in my localhost, Add a connection through Data Source (ODBC) in ctrl panel and test connection succeed. Now I want to show the query on my default.aspx page so that I can do the insert / update / delete my table data in MySQL. Can anyone help me?

+1  A: 

The recommended way of connecting to MySQL in .NET is using ADO.NET connector. You could download it from here. It represents a .NET assembly that you need to reference in your application. And here's a sample code:

using (var cn = new MySqlConnection("Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;"))
using (var cmd = cn.CreateCommand())
{
    cn.Open();
    cmd.CommandText = "select * from sometable";
    using (var reader = cmd.ExecuteReader())
    {
        while (reader.Read())
        {
            // read values
        }
    }
}
Darin Dimitrov
I've already add the reference in my solution explorer,but where I must put these code?It seems the code not in VB language
Daniel Budihardja
As you didn't specify what language you work with in your question I assumed C#. You could use an online converter (http://www.developerfusion.com/tools/convert/csharp-to-vb/) to translate to VB.NET.
Darin Dimitrov