开发者

Connect ASP Visual Web Developer 2008 to MySQL with ODBC 3.51

开发者 https://www.devze.com 2022-12-15 21:43 出处:网络
Can Anybody tell me how to connect ASP to MySQL database.. I have already install MySQL in my localhost,

Can Anybody tell me how to connect ASP to MySQL database.. I have already install MySQL in my localhost, A开发者_开发知识库dd 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?


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
        }
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消