how to import data from mysql database to datagridview

c#, datagridview, mysql, mysql-workbench

Solution

You can use the following code to read the table data from database and display it into data gridview.

string connectionString = ""; //Set your MySQL connection string here.
string query =""; // set query to fetch data "Select * from  tabelname"; 
using(MySqlConnection conn = new MySqlConnection(connStr))
{
    using(MySqlDataAdapter adapter = new MySqlDataAdapter(query, conn))
    {
        DataSet ds = new DataSet();
        adapter.Fill(ds);
        DataGridView1.DataSource= ds.Tables[0];
    }
}

Problem

i have a table in mysql database named cms.order and i am working on a widows form using C#. How can i show the data from the table in database in the datagridview of the windows form

Original source