这句好象错了,    table.Rows[dataGrid1.CurrentRowIndex].Delete();
我是这样实现的:
for (i=(DataGrid1.Items.Count-1);i>=0;i--)
{
CheckBox cb = (CheckBox)DataGrid1.Items[i].Controls[13].Controls[1];
if ( cb.Checked == true)
try 
{ ds.Tables["aa"].Rows[(DataGrid1.CurrentPageIndex) * 4 + i].Delete();

}
catch
{
}
finally
{
}               
}

解决方案 »

  1.   

    我也遇到过这样的问题,但是这样为什么只可以从DATASET中删除不可以从DATABASE中真正的把他删除!我是用SQL删除的
      

  2.   

    你看看你的adapter的DeleteCommand是否有问题。
      

  3.   

    试试这个
    try
    {
    if(dataGrid1.CurrentRowIndex!= -1)
    {
    DataTable table = ds.Tables["a"];
    dv = table.DefaultView;
    dv.AllowDelete = true;
    dv.Delete(dataGrid1.CurrentRowIndex);
    if(ds.HasChanges())
    {
    da.Update(ds,"a");
    }
    ds.Tables["a"].AcceptChanges();
    }
    else
    {
    MessageBox.Show("请选择一行数据");
    }
    }
    catch(SqlException ex)
    {
    MessageBox.Show(ex.Message);
    ds.Tables["a"].RejectChanges();

    }
      

  4.   

    设置一下你的adapter.deletecommand
      

  5.   

    请问我该怎么设置adapter.deletecommand呢,我不是用的组件。
      

  6.   

    SqlCommand deletecommand1 = new SqlCommand();
    adapter.deletecommand = this.deletecommand1;
    this.deletecommand1.CommandText = "delete xxx.....";
    this.deletecommand1.connection =this.conn;
    .....
      

  7.   

    this.deletecommand1.CommandText = "delete xxx....."引号里的东西具体怎么定义,我不怎么懂,是不是还要定义映射?