ASP.NET链接MySQL

1.需要有Mysql.Data.dll,有区分版本的,这个要注意下


2.连接字符串代码

using MySql.Data.MySqlClient;

namespace ConnectMySql
{
    class Class1
    {
        public MySqlDataReader GetData()
        {
            string connection = "server=localhost;user id=root;password=123456;database=ABC; pooling=true;";
            MySqlConnection conn = new MySqlConnection(connection);
            string sqlQuery = "SELECT * FROM Article";
            MySqlCommand comm = new MySqlCommand(sqlQuery, conn);
            conn.Open();
            MySqlDataReader dr = comm.ExecuteReader();
            conn.Close();
            return dr;
        }
    }
}

内容引用来源:http://www.tuicool.com/articles/yyUFfe

你可能感兴趣的:(ASP.NET)