我正在开发一个winforms项目,我在Form_Load方法中有以下代码。但它不起作用。谁能帮我?
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;
答案 0 :(得分:2)
尝试直接采购数据集中的表格:
dataGridView1.DataSource = ds.Tables[0];
答案 1 :(得分:0)
SqlDataAdapter sda = new SqlDataAdapter(scmd, conn);
dataTable dt = new DataTable();
sda.Fill(dt);
dataGridView1.DataSource = dt;