C# 无法在WinForms中的DataGridView中查看表

C# 无法在WinForms中的DataGridView中查看表,c#,ado,C#,Ado,请帮我找到解决办法 我无法获取WinForms的datagridview控件中显示的数据。 我尝试了连接和断开连接的架构,但仍然看不到数据 以下是我的代码1: SqlDataAdapter da = new SqlDataAdapter("Select * from employ", con); DataSet ds = new DataSet(); da.Fill(ds); bindingSource1.DataSource = ds; dataGridView1.DataSourc

请帮我找到解决办法

我无法获取WinForms的datagridview控件中显示的数据。 我尝试了连接和断开连接的架构,但仍然看不到数据

以下是我的代码1:

 SqlDataAdapter da = new SqlDataAdapter("Select * from employ", con);
 DataSet ds = new DataSet();
 da.Fill(ds);
 bindingSource1.DataSource = ds;
 dataGridView1.DataSource = bindingSource1;
&这是我的代码2:

 SqlCommand cmd = new SqlCommand("Select * from employ", con);
 using (SqlDataReader dr = cmd.ExecuteReader())
 {
     BindingSource b1 = new BindingSource();
     b1.DataSource = dr;
     dataGridView1.DataSource = b1;
 }
哪里错了?我可以在调试时看到填充的表,但在UI中看不到。

需要添加

 dataGridView1.Databind()

设置数据源后

添加一个C#标记以获取更多视图DataGridView没有Databind()方法。哦,对不起,webforms