void filldata()
{
DataGrid1.DataSource = dset.Tables [0];
DataGrid1.DataBind();
}
public void delete(object sender,DataGridCommandEventArgs e)
{
dset.Tables [0].Rows.RemoveAt(e.Item.ItemIndex);
dset.Tables [0].AcceptChanges ();
update();
filldata();
}
void update()
{
SqlCommandBuilder build=new SqlCommandBuilder (adapter);
adapter.UpdateCommand = build.GetUpdateCommand();
adapter.DeleteCommand = build.GetDeleteCommand();
adapter.Update(dset,"user");
}
adapter是一个全局的SqlDataAdapter,dset也是一个全局的DataSet,我在datagrid中放了一个删除按钮,就是datagrid自己带的那个,点删除以后datagrid中显示是没了,但是数据库中还有,重新进入页面就又出来了,你们说说会是什么原因
{
DataGrid1.DataSource = dset.Tables [0];
DataGrid1.DataBind();
}
public void delete(object sender,DataGridCommandEventArgs e)
{
dset.Tables [0].Rows.RemoveAt(e.Item.ItemIndex);
dset.Tables [0].AcceptChanges ();
update();
filldata();
}
void update()
{
SqlCommandBuilder build=new SqlCommandBuilder (adapter);
adapter.UpdateCommand = build.GetUpdateCommand();
adapter.DeleteCommand = build.GetDeleteCommand();
adapter.Update(dset,"user");
}
adapter是一个全局的SqlDataAdapter,dset也是一个全局的DataSet,我在datagrid中放了一个删除按钮,就是datagrid自己带的那个,点删除以后datagrid中显示是没了,但是数据库中还有,重新进入页面就又出来了,你们说说会是什么原因
dset.Tables [0].AcceptChanges ();
dset.Update();
只是修改了本地的数据副本,所以datagrid中是没了。
dataset是静态的数据集,本身跟数据库没有联系,dateadapter是联系本地dataset中的数据和数据库数据之间的纽带。
"user"表是Tables[0]么?