Home All Groups Group Topic Archive Search About

Accessing deleted rows problem

Author
9 Jan 2007 9:56 PM
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 :-)

Author
9 Jan 2007 10:44 PM
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.
--
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/

Show quote
"Rastko Soskic" <rastkosos***@yahoo.com> wrote in message
news:%23%23MBYkDNHHA.4992@TK2MSFTNGP04.phx.gbl...
> 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 :-)
>
>
Author
10 Jan 2007 7:10 AM
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!

Show quote
"Miha Markic [MVP C#]" <miha at rthand com> wrote in message
news:uJkft$DNHHA.3312@TK2MSFTNGP03.phx.gbl...
> 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" <rastkosos***@yahoo.com> wrote in message
> news:%23%23MBYkDNHHA.4992@TK2MSFTNGP04.phx.gbl...
>> 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 :-)
>>
>>
>

AddThis Social Bookmark Button