Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/58.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在DataGridView中显示数据时出现问题_C#_Mysql_Database_Visual Studio - Fatal编程技术网

C# 在DataGridView中显示数据时出现问题

C# 在DataGridView中显示数据时出现问题,c#,mysql,database,visual-studio,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=''");

我正在尝试使用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);
 }

您的连接字符串正确吗?我查找了MySql连接字符串,它似乎使用了“Uid”而不是“user”。试试看。你有什么错误吗?如果是,请提供。没有任何错误。因此,我甚至不知道我哪里出了问题。当我单击按钮1时,什么也没有发生。您能不能取消BindingSource并只设置dgView.DataSource=dtable@Navomishetty你有没有尝试过单步执行代码?如果没有,请在button1\u Click方法周围添加一个try-catch块,并逐步完成代码。如果出现任何错误,请告诉我们。