C# 在DataGridView中显示数据时出现问题
我正在尝试使用c#在DataGridView上显示我的mysql数据库表。但是什么也没发生。请告诉我我的代码哪里出错了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=''");
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块,并逐步完成代码。如果出现任何错误,请告诉我们。