Simply.com is available in english

Conexiune la MySQL cu .NET Connector

Următorul exemplu de cod poate fi utilizat pentru a obține acces la o bază de date MySQL prin intermediul .NET Connector al MySQL:

Poți să implementezi driverul MySQL pe gazduirea ta web, poate fi descărcat de pe site‑ul MySQL.

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();

Articol din categoria de suport: ASP & ASP.NET

Alte articole relevante