DeletedRowInaccessibleException
I have an ASP.NET page with a DataGrid. I populate the grid with
data from a table in SQL Server using a DataSet and DataTable
and allow the user to do various operations (Edit, Delete etc)
on the data in DataGrid.
When the user is satisfied with his changes I want him to press
a 'Save to Database' button to commit everything to the DB. I
don't want round trips to the database for each change he makes,
he has to consciously commit them all at once.
So in the clickevent for the 'Save to Database' button I do
DataTable dt = ds.Tables["Distributions"]; // ds is my DataSet
foreach (DataRow dr in dt.Rows)
{
switch (dr.RowState)
{
case DataRowState.Added :
{
ins( ... ); // helper method to do a SQL INSERT
break;
}
case DataRowState.Deleted :
{
del(Int32.Parse(dr["DistributionID"].ToString())); //helper method to do a SQL DELETE
}
.....
This fails with the DeletedRowInaccessibleException, which says:
"Deleted row information cannot be accessed through the row"
which seems fair enough, but I need to get the key of that
row so I can do the SQL DELETE.
I found a Microsoft knowledge base article which shows how to
use a CurrencyManager object, create a DataView etc to get
to the underlying data: but CurrencyManager is part of the
Windows.Forms namespace and I don't think I can use it in a
webform.
So, how do I do this?
Will Irwin
|