.Net and MySQL: Example of using MySQL and .Net: A simple example of useing Connector/Net 5.2 to connect with MySQL from .Net

Follow this process:

  1. Download Connector/Net 5.2.
  2. Unzip the binaries. You will find 3-4 dlls along with other files.
  3. Add reference to mysql.data.dll, in your project.
  4. You can connect to MySQL throw code, as described below:

String conString = “server=server_name; user id=user_name;

password=password; database=db_name; pooling=false;”;

String queryString = “select * from employee;”;

using (MySqlConnection mySqlConnection = new MySqlConnection(conString))

{

using (MySqlDataAdapter adapter = new MySqlDataAdapter(queryString, mySqlConnection))

{

DataTable dt = new DataTable();

adapter.Fill(dt);

dataGridView1.DataSource = dt;

}

}

Published in: on July 27, 2009 at 8:39 pm  Leave a Comment  
Tags: , , , , , ,