Best practice to Enumerate BO to delete current row...


Author
Message
Michel Levy
Michel Levy
StrataFrame User (451 reputation)StrataFrame User (451 reputation)StrataFrame User (451 reputation)StrataFrame User (451 reputation)StrataFrame User (451 reputation)StrataFrame User (451 reputation)StrataFrame User (451 reputation)StrataFrame User (451 reputation)StrataFrame User (451 reputation)
Group: StrataFrame Users
Posts: 193, Visits: 9K
Hi Les,

glad to see you here!

Edhy Rijo
E
StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Les,



Glad to see you in the StrataFrame community, it will be very positive for all.



About your sample approach, it is interesting, thanks, I will test it with my project.

Edhy Rijo

Charles R Hankey
Charles R Hankey
Advanced StrataFrame User (964 reputation)Advanced StrataFrame User (964 reputation)Advanced StrataFrame User (964 reputation)Advanced StrataFrame User (964 reputation)Advanced StrataFrame User (964 reputation)Advanced StrataFrame User (964 reputation)Advanced StrataFrame User (964 reputation)Advanced StrataFrame User (964 reputation)Advanced StrataFrame User (964 reputation)
Group: Forum Members
Posts: 524, Visits: 30K
Les !!



How nice to see you here after all these years. I believe the last time I saw you I was manning the F1 booth near yours at ... Ft. Lauderdale? Palm Springs? I remember Ceil was running around taking pictures. ( man I miss her)



Anyway, welcome to Strataframe. I think you are going to love it and I know your contribution to this community will be very welcome. If you've not yet had the opportunity to meet the Taylor family I know you will enjoy each other.



There is a lot of real-world pragmatism and appreciation of "Microsoft realities" built into this framework and I've found it invaluable in getting very productive in .NET.



Hope we see a lot of you here.



( for the benefit of non-Fox lurkers who may not know him - Les is one of the best known authors, teachers and speakers in the Foxpro world as well as being one of the most colorful and interesting characters in anybody's world BigGrin )
Les Pinter
Les Pinter
StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)StrataFrame Team Member (73 reputation)
Group: Forum Members
Posts: 43, Visits: 213
Hi Edhy,

   I used this with a little test database containing a Flag_DeletedRecord column, and it worked fine:

{BO1.Filter = "Flag_DeletedRecord = True";
 if (BO1.Count > 0) { do { BO1.DeleteCurrentRow(); } while (BO1.Count > 0); }
     BO1.Save(); BO1.Filter = "";}

   I hope this relates to what you're doing. Good seeing your name again after all these years...

Les


Edhy Rijo
E
StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Paul Chase (06/19/2009)
Edhy, if you loop through backwards and delete then current index won't get out of whack.




Hi Paul,



Just to let you know that today I came across a situation where your suggestion fitted perfectly.



Thanks again for sharing.

Edhy Rijo

Edhy Rijo
E
StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Paul,



Thanks, I did not even consider that option and sure it does make sense. I will test it.

Edhy Rijo

Paul Chase
Paul Chase
Advanced StrataFrame User (598 reputation)Advanced StrataFrame User (598 reputation)Advanced StrataFrame User (598 reputation)Advanced StrataFrame User (598 reputation)Advanced StrataFrame User (598 reputation)Advanced StrataFrame User (598 reputation)Advanced StrataFrame User (598 reputation)Advanced StrataFrame User (598 reputation)Advanced StrataFrame User (598 reputation)
Group: Forum Members
Posts: 414, Visits: 2.8K
Edhy,

If you loop through backwards and delete then current index won't get out of whack.

 

For i As Integer = MyBO.Count - 1 To 0 Step -1

 If MyBO.somefield = Something Then

Delete

Endif

Next


Edhy Rijo
E
StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)StrataFrame VIP (4.7K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi guys,



I have a BO filtered with records that needs to be deleted from the database, I am trying to use BO.GetEnumerable() to go trough each record and delete it, but of course the once it is deleted, it is removed from the currentview and mess the CurrentRowIndex, here is the code I tried:



Me.BizTransactionItemsStock1.Filter = "Flag_DeletedRecord = True"

For Each StockBO As bizTransactionItemsStock In Me.BizTransactionItemsStock1.GetEnumerable()

StockBO.DeleteCurrentRow(True)

Next





Then I simply decided to use another For..EndFor so the CurrentRowIndex will have no effect like this:



Me.BizTransactionItemsStock1.Filter = "Flag_DeletedRecord = True"

Dim lnReccount As Integer = Me.BizTransactionItemsStock1.Count

If lnReccount > 0 Then

For i As Integer = 1 To lnReccount

Me.BizTransactionItemsStock1.DeleteCurrentRow(True)

Next

End If





This code is working for me, but I want to make sure there is not better way to handle this? of course, after this, a BO.Save() will actually delete the records from the database.



Thanks!



P.S.

To all developers, be aware of the BO.Filter and BO.Sort effects which will immediately remove any record which does to comply with the Filter and for the Sort, it may mess your CurrentRowIndex as well while trying to enumerate the BO. These are very powerful features Smile, but also very tricky BigGrin

Edhy Rijo

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search