Accessing deleted rows problem

R

Rastko Soskic

Hi everyone!
As stated in subject I have problem with accessing deleted rows within
dataset,
that is, deleted rows within table contained in dataset.
Dataset is strongly typed (generated by designer).
I need to say that I've done this by following tips in MSDN.

First I create dataset, then entity I want to add.

public void Sample()
{
TypedDataSet ds = new TypedDataSet();
ds.Tables["TableName"].Rows.Add(entity.CreationParams); //
CreationParams is property

// which returns object[] with required values

// Adding row works perfectly!
// Then, I find and delete row
DataRow dr = ds.Tables["TableName"].Rows.Find(entity.Identity) //
Identity is property
dr.Delete();
// which returns object[] with PK values

// Removing row also works perfectly!
// Now, I should be able to get those rows with "Deleted" status this
way:
DataView dv = new DataView(ds.Tables.["TableName"], "", "",
DataViewRowState.Deleted);
// But!!! dv, that is dv.Table.Rows is EMPTY!!!
// Alternatively, I've tried with ds.Tables["TableName"].Select(null,
null, DataViewRowState.Deleted);
// but no luck there :)
}

My question is simple :) What I am doing wrong?
Any advice, tip, suggestion, help is appreciated. Thank you very much :)
 
M

Miha Markic [MVP C#]

Hi Rastko,

That's because newly added rows are removed from collection when deleted.
If the row isn't new at the deletion time then it is persisted (marked as
Deleted) so the adapter can delete it from the database.
Try calling ds.AcceptChanges() after adding your new row and row will be
marked as deleted when you delete it.
 
R

Rastko Soskic

Hey, thanks man! Your answer is what is not stated in MSDN :)
Maybe you can urge at MS to correct mistake :))) (just kidding, maybe I
should dig deeper next time)
Thanks again!

Miha Markic said:
Hi Rastko,

That's because newly added rows are removed from collection when deleted.
If the row isn't new at the deletion time then it is persisted (marked as
Deleted) so the adapter can delete it from the database.
Try calling ds.AcceptChanges() after adding your new row and row will be
marked as deleted when you delete it.
--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Rastko Soskic said:
Hi everyone!
As stated in subject I have problem with accessing deleted rows within
dataset,
that is, deleted rows within table contained in dataset.
Dataset is strongly typed (generated by designer).
I need to say that I've done this by following tips in MSDN.

First I create dataset, then entity I want to add.

public void Sample()
{
TypedDataSet ds = new TypedDataSet();
ds.Tables["TableName"].Rows.Add(entity.CreationParams); //
CreationParams is property

// which returns object[] with required values

// Adding row works perfectly!
// Then, I find and delete row
DataRow dr = ds.Tables["TableName"].Rows.Find(entity.Identity) //
Identity is property
dr.Delete(); // which returns object[] with PK values

// Removing row also works perfectly!
// Now, I should be able to get those rows with "Deleted" status this
way:
DataView dv = new DataView(ds.Tables.["TableName"], "", "",
DataViewRowState.Deleted);
// But!!! dv, that is dv.Table.Rows is EMPTY!!!
// Alternatively, I've tried with ds.Tables["TableName"].Select(null,
null, DataViewRowState.Deleted);
// but no luck there :)
}

My question is simple :) What I am doing wrong?
Any advice, tip, suggestion, help is appreciated. Thank you very much :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top