Connection to MySQL with .NET Connector

The following code example can be used to access a MySQL Database through MySQL .NET Connector:

You can deploy the MySQL driver by yourself to your web space, it can be downloaded from MySQL's website.

using MySql.Data.MySqlClient;

MySqlConnection con = new MySqlConnection();
string mysql = "Server=[server];Database=[database];User=[brugernavn];pwd=[password]";
con.ConnectionString = mysql;
con.Open();

MySqlCommand cmd = con.CreateCommand();
cmd.CommandText = "SELECT * FROM TestTabel";
cmd.Connection = con;

MySqlDataReader reader = cmd.ExecuteReader();

while (reader.Read())
{
Response.Write(reader.GetValue(0).ToString());
}

cmd.Dispose();
con.Close();

Article from category ASP & ASP.NET