在DataGridView中显示数据的麻烦

时间:2015-02-18 18:28:02

标签: c# mysql database visual-studio

我正在尝试使用c#在DataGridView上显示我的mysql数据库表。但是没有发生。请告诉我我的代码在哪里出错了

   private void button1_Click(object sender, EventArgs e)
         {
           MySqlConnection conn = new MySqlConnection("Server = localhost; Database=project; user=root;password=''");
           conn.Open();
            string query = "SELECT * FROM billing";

         MySqlDataAdapter bills = new MySqlDataAdapter(query, conn);
         MySqlCommandBuilder cbuilder = new MySqlCommandBuilder(bills);
         DataTable dtable = new DataTable();
        bills.Fill(dtable);
         //the DataGridView
         DataGridView dgView = new DataGridView();

         //BindingSource to sync DataTable and DataGridView
         BindingSource bSource = new BindingSource();

         //set the BindingSource DataSource
         bSource.DataSource = dtable;

         //set the DataGridView DataSource
         dgView.DataSource = bSource;
         bills.Update(dtable);
 }

0 个答案:

没有答案