datagridview绑定失败

来源:百度知道 编辑:UC知道 时间:2024/05/31 11:42:25
以下我的写法,在窗体load时能出数据,可是在执行增删改查后再绑定(也是这几句)就没反应了,还是一开始显示的数据。不知道为什么,请高手指点!比如说查询出一条数据,调试时在(if (ds != null && ds.Tables[0].Rows.Count >0))这句时显示确实是一条数据,可执行绑定之后控件数据没反应。还是load时的数据。
strSqlSelect = "select gzbh as '故障编号',gzmc as '故障名称',gzxx as '故障信息',clff as '处理方法' from guzhangguanli where " + strSql;
DataSet ds = new DataSet();
SqlDataAdapter ad = new SqlDataAdapter(strSqlSelect, conn);
ad.Fill(ds);
if (ds != null && ds.Tables[0].Rows.Count >0)
{
this.dataGridView1.DataSource = ds.Tables[0];
}
else
{
MessageBox.Show("没有满足条件的数据!", "查询", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
我以前用2003,现在用2005的,我也想用,但是没有this.dataGridView1.DataBind(); 这个。
this.dataGridView1.Refresh(); 这个也不行。
this.dataGridView1.

this.dataGridView1.DataSource = ds.Tables[0];
改成
this.dataGridView1.DataSource = ds.Tables[0].DefaultView;
如果你要显示特定的列就需要一个个设置
如果没有进行添加删除行为的话,我觉得可以将不满足条件的隐藏掉
dataGridView1.DataSource = ds.Tables[0];
我写的一个程序就是这样=就没问题的

DataSet ds = new DataSet();
SqlDataAdapter ad = new SqlDataAdapter(strSqlSelect, conn);
ad.Fill(ds);
if (ds != null && ds.Tables[0].Rows.Count >0)
{
this.dataGridView1.Columns.Clear();
this.dataGridView1.DataSource = ds.Tables[0];
}

试试。

datagridview1.Refresh();
看看

没绑定吧?