怎么用数据集在datagridview中显示查询结果
private void button1_Click(object sender, EventArgs e)
{
string cstr = @"Data Source=.;Initial Catalog=student;Integrated Security=True";
//string sql = string.Format("select * from {0}",comboBox1.Text);
string sql = "select * from Student";
DataTable ta = new DataTable();
SqlConnection conn = new SqlConnection(cstr);
SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
SqlCommandBuilder scb = new SqlCommandBuilder(sda);
sda.Update(ta);
dataGridView1.DataSource = ta;
}
------解决方案--------------------sda.Update(ta);
=>
sda.Fill(ta);
------解决方案--------------------http://blog.csdn.net/21aspnet/article/details/1540301
------解决方案--------------------在dataGridView1_CellEndEdit事件里面写更新方法。
------解决方案--------------------SqlDataAdapter sda = new SqlDataAdapter(sql, conn);
DataSet ds=new DataSet();
sda.fill(ds);
dataGridView1.DataSource = ds;