Connecting to a mySQL database using asp.net

Right click on References, then select "Add Reference". Browse and select Mysql.Data.dll.

The dll should be found in the installation directory of the connector you downloaded.

enter image description here

Finally, in code:

using MySql.Data.MySqlClient;

And, sample connection:

MySqlConnection connection = new MySqlConnection("Database=database_name;Data Source=server_domain_or_ip;User Id=mysql_user;Password=mysql_password");
connection.Open();

MySqlCommand command =  connection.CreateCommand();
command.CommandText = "select * from mytable";
MySqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
  //reader.GetString(0)
  //reader["column_name"].ToString()
}
reader.Close();

Tags:

Mysql

Asp.Net