这句好象错了, 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
{
}
}
我是这样实现的:
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
{
}
}
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();
}
adapter.deletecommand = this.deletecommand1;
this.deletecommand1.CommandText = "delete xxx.....";
this.deletecommand1.connection =this.conn;
.....