在ASP.NET中,GataGrid中有一个删除按纽列,点击该删除按纽,可以在GataGrid中删除一行,但没有更新到数据库,不知道哪里出现了问题,请教各位高手,部分代码如下:
//绑定DataSet到DataGrid1
DataGrid1.DataSource = ds;
DataGrid1.DataBind(); DataView dv ;
dv = new DataView( ds.Tables["notice"]);
dv.RowFilter = "id= " +e.Item.Cells[0].Text.Trim();
if (dv.Count > 0)
{
dv.Delete(0);
}
if (ds.HasChanges())
{
oleDbDataAdapter1.Update(ds,"notice"); //该句也能执行到,就是更新不了数据库
}
//绑定DataSet到DataGrid1
DataGrid1.DataSource = ds;
DataGrid1.DataBind(); DataView dv ;
dv = new DataView( ds.Tables["notice"]);
dv.RowFilter = "id= " +e.Item.Cells[0].Text.Trim();
if (dv.Count > 0)
{
dv.Delete(0);
}
if (ds.HasChanges())
{
oleDbDataAdapter1.Update(ds,"notice"); //该句也能执行到,就是更新不了数据库
}
SqlCommandBuilder sc = new SqlCommandBuilder(da);
dv = new DataView( ds.Tables["notice"]);
dv.RowFilter = "id= " +e.Item.Cells[0].Text.Trim();
if (dv.Count > 0)
{
dv.Delete(0);
}
改为:
DataTable dt = ds.Tables["notice"];
DataRow dr = dt.Select("id= " +e.Item.Cells[0].Text.Trim());
dr.Delete();
if (dr != null)
{
dr.Delete();
}
如果再不行的话,请参考:
http://blog.csdn.net/chengking/archive/2005/08/26/465874.aspx