M
marc.l.caron
It appears to me that using the SetModified() doesn't force the data
changes into the database. I'm thinking it is doing comparisons
between the DataRowVersion's. I say this because of my following
problem.
I have a scenario where the best way to handle the data is to take
datatable table1. While processing it's contents if a row exhibits
problems it has a status field and description updated and the changes
accepted. (to the datatable only) then the row is Deleted (again in
the data table only)
All "deleted" rows are then pulled out of table1
via .GetChanges(DataRowState.Deleted) and it results in a deletedItems
table.
DataTable deletedItems = table1..GetChanges(DataRowState.Deleted);
Now what I actually need to do is apply the changes made to these
deleted rows to the database. So first I reject all the deletes.
Then mark every row as modified. I then call update on the data
adapter. The call to update returns the correct # of modified rows
but nothing is persisted to the database. So here's some simple code
to show the concept.
<code>
foreach (DataRow row in table1)
{
if (every 10 rows)
{
row["Status"] = "X";
row["Description"] = "This is a 10th row";
row.AcceptChanges(); // If we don't do this here the the above 2
values are not accessable after the delete
row.Delete();
}
}
DataTable deleteditems = table1.GetChanges(DataRowState.Deleted);
table1.AcceptChanges();
deleteditems.RejectChanges();
foreach (DataRow row in deleteditems)
{
row.SetModified();
}
int modified = table1DataAdapter.Update(deleteditems);
// modified comes out right. But no changes get to the database.
</code>
Obviously my reason for marking the rows deleted is way more complex
then that but that gives the idea.
Anyone have any ideas? I've been working on this all day and can't
find a reason why nothing updates.
thanks
changes into the database. I'm thinking it is doing comparisons
between the DataRowVersion's. I say this because of my following
problem.
I have a scenario where the best way to handle the data is to take
datatable table1. While processing it's contents if a row exhibits
problems it has a status field and description updated and the changes
accepted. (to the datatable only) then the row is Deleted (again in
the data table only)
All "deleted" rows are then pulled out of table1
via .GetChanges(DataRowState.Deleted) and it results in a deletedItems
table.
DataTable deletedItems = table1..GetChanges(DataRowState.Deleted);
Now what I actually need to do is apply the changes made to these
deleted rows to the database. So first I reject all the deletes.
Then mark every row as modified. I then call update on the data
adapter. The call to update returns the correct # of modified rows
but nothing is persisted to the database. So here's some simple code
to show the concept.
<code>
foreach (DataRow row in table1)
{
if (every 10 rows)
{
row["Status"] = "X";
row["Description"] = "This is a 10th row";
row.AcceptChanges(); // If we don't do this here the the above 2
values are not accessable after the delete
row.Delete();
}
}
DataTable deleteditems = table1.GetChanges(DataRowState.Deleted);
table1.AcceptChanges();
deleteditems.RejectChanges();
foreach (DataRow row in deleteditems)
{
row.SetModified();
}
int modified = table1DataAdapter.Update(deleteditems);
// modified comes out right. But no changes get to the database.
</code>
Obviously my reason for marking the rows deleted is way more complex
then that but that gives the idea.
Anyone have any ideas? I've been working on this all day and can't
find a reason why nothing updates.
thanks