DataGridView绑定不起作用

问题描述:

我正在使用winforms项目,并且我在Form_Load方法中有以下代码。但它不起作用。谁能帮我?DataGridView绑定不起作用

SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Sella.Properties.Settings.Database1ConnectionString1"].ConnectionString); 
// A SqlCommand object is used to execute the SQL commands. 
SqlCommand scmd = new SqlCommand("Select * From CustCalls", conn); 
// A SqlDataAdapter uses the SqlCommand object to fill a DataSet. 
SqlDataAdapter sda = new SqlDataAdapter(scmd); 
// Create and Fill a new DataSet. 
DataSet ds = new DataSet(); 
sda.Fill(ds); 

dataGridView1.DataSource = ds; 
+1

您可以定义 “它不工作”?没有显示在网格中,或者是否有错误。如果出现错误,请将其编辑到您的问题中。 – LarsTech 2012-01-17 20:02:36

+0

DataBindingComplete事件是否正在触发? – NicoRiff 2012-01-17 20:03:21

尝试采购直接到数据集中的表:

dataGridView1.DataSource = ds.Tables[0]; 

SqlDataAdapter sda = new SqlDataAdapter(scmd, conn); 

dataTable dt = new DataTable(); 

sda.Fill(dt); 

dataGridView1.DataSource = dt; 
+0

它更好地描述你的答案一点 – 2012-10-20 06:46:08