delete row in disconnected dataSet 
Author Message
 delete row in disconnected dataSet

Once you deleted a DataRow, none of its fields are accessible;
thiugh you can count how many rows were deleted, by filtering on the
DataView's RowStateFilter,
you can't access the fields themselves.

Now this is very restrictive in a disconnected environment :

suppose you have 2 tables, T1 and T2, where field F2 of T2 references field
F1 of T1;
and suppose you cannot set a foreign key relationship, for some good reason;

suppose you fetch a dataSet DS1 containing T1 from the server,
and then continue working on the dataSet in a disconnected way, for some
days;
and suppose you delete a row R1;

suppose you syncronize after a few days with the server, by doing an Update
on the dataSet DS1;

what you now want to happen, is that the server deletes all rows R2 from T2
if they reference R1;
but, though the server can update (=delete) row R1, it can not use R1 to
find all associated R2's,
because the fields of R1 are not accessible anymore;

how can you ever delete R1 without having immediate (not disconnected)
access to the server ?
or without recurring to an artificial mechanism defeating the
self-containing purpose of a dataSet ?



Sun, 21 Nov 2004 22:03:06 GMT  
 delete row in disconnected dataSet
Walter,

    I can't imagine any good reason why you couldn't have a foreign key
relationship.  Even if there was one, you have to adjust the processing
somewhere down the line to acknowledge this relationship, which you are not
doing.  In order to reflect this in the DataSet class, you have to set up a
DataRelation instance between the two DataTables that will cause the child
rows to be deleted when the parent row is deleted.

    Hope this helps.

--
               - Nicholas Paldino [.NET MVP]


Quote:
> Once you deleted a DataRow, none of its fields are accessible;
> thiugh you can count how many rows were deleted, by filtering on the
> DataView's RowStateFilter,
> you can't access the fields themselves.

> Now this is very restrictive in a disconnected environment :

> suppose you have 2 tables, T1 and T2, where field F2 of T2 references
field
> F1 of T1;
> and suppose you cannot set a foreign key relationship, for some good
reason;

> suppose you fetch a dataSet DS1 containing T1 from the server,
> and then continue working on the dataSet in a disconnected way, for some
> days;
> and suppose you delete a row R1;

> suppose you syncronize after a few days with the server, by doing an
Update
> on the dataSet DS1;

> what you now want to happen, is that the server deletes all rows R2 from
T2
> if they reference R1;
> but, though the server can update (=delete) row R1, it can not use R1 to
> find all associated R2's,
> because the fields of R1 are not accessible anymore;

> how can you ever delete R1 without having immediate (not disconnected)
> access to the server ?
> or without recurring to an artificial mechanism defeating the
> self-containing purpose of a dataSet ?



Sun, 21 Nov 2004 22:21:38 GMT  
 delete row in disconnected dataSet

Quote:

>  I can't imagine any good reason why you couldn't have a foreign key
> relationship.

legacy DB where the field F2 is refering to multiple tables, depending on
the value of another field

Quote:
> Even if there was one, you have to adjust the processing
> somewhere down the line to acknowledge this relationship, which you are
not
> doing.  In order to reflect this in the DataSet class, you have to set up
a
> DataRelation instance between the two DataTables that will cause the child
> rows to be deleted when the parent row is deleted.

I do not want to fetch DataSet DS2 with Table T2 just in order to perform
the delete.
I want the server to take care of the delete of the child rows, and
preferably in a disconnected way.

most importantly :
the problem is that, supposing that you take all the child rows into your
dataset, with a DataRelation, then, once you are disconnected, the master
row can still 'grow' child rows from another user; I want them to be deleted
as well when I reconnect and do the Update to delete the master row;

I wanted to avoid the restriction to be able to perform a delete only when
the user is on-line;
that is, I could ask the server to delete the child rows just _before_ the
delete, and then delete the master row;
but what if the user is off-line ?



Sun, 21 Nov 2004 22:50:02 GMT  
 delete row in disconnected dataSet
Ok Nicholas,
I figured out what the problems were :

1. ===
When the server gets the dataset with a deleted row in it, you could get the
original Rows with

    DataRow [] delRows = table.Select (null, null,
DataViewRowState.Deleted);

However this does not work when the Delete happened at the clients, and the
Select happens at the servers, because of a bug in Serialization, see
http://groups.google.com/groups?hl=en&lr=&threadm=OoEQbS9lBHA.856%40t...
p03&rnum=8&prev=/groups%3Foi%3Ddjq%26as_q%3Ddotnet%2Bdatarowstate%2Bdeleted

Apparently this bug is still there; you have to write a custom select and
copy all the deleted rows first, like :

    private DataRow [] MySelect (DataTable dataTable, DataRowState
dataRowState) {
        ArrayList rows = new ArrayList();
        foreach (DataRow row in dataTable.Rows) {
            if( row.RowState == dataRowState ) {
                rows.Add(row);
            }
        }
        return (DataRow[])rows.ToArray(typeof(DataRow));
    }

2. ===
Then you can read the original rows with

    foreach (DataRow delRow in delRows) {
        System.Guid id =  (System.Guid) delRow ["ID",
DataRowVersion.Original];
            ....
    }

3. ===
Notice that, even  if you use typed dataSets, you need to resort to the
untyped rows, in order to get to the fields



Mon, 22 Nov 2004 03:22:58 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. trouble deleting a row from a dataset

2. How to connect to a Jet database, insert a row, and disconnect via MFC

3. DataSet Rows

4. Adding A New Row To A Dataset

5. DataSet Issue : How do I add a Row to a DataTable with Identity Column

6. passing a SQL datareader or dataset with 1000 rows and 10 columns

7. XmlDataDocument.DataSet.ReadXML only returns 1 row

8. Searching specific row in the dataGrid and dataSet

9. Current dataset data row...

10. Can't delete rows from a table in SQL Server 2000 without a primary key

11. Delete Rows from XmlDocument after binding to a grid

12. DataGrid - Blocking a row delete

 

 
Powered by phpBB® Forum Software