| | | StrataFrame VIP
       
Group: StrataFrame Users Last Login: Today @ 12:36:01 PM Posts: 1,396, Visits: 7,912 |
| 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 , but also very tricky 
|
| | | | 
StrataFrame User
       
Group: StrataFrame Users Last Login: 02/23/2010 3:49:47 PM Posts: 401, Visits: 2,775 |
| | 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 |
| | | | StrataFrame VIP
       
Group: StrataFrame Users Last Login: Today @ 12:36:01 PM Posts: 1,396, Visits: 7,912 |
| Hi Paul,
Thanks, I did not even consider that option and sure it does make sense. I will test it.
|
| | | | StrataFrame VIP
       
Group: StrataFrame Users Last Login: Today @ 12:36:01 PM Posts: 1,396, Visits: 7,912 |
| 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.
|
| | | | StrataFrame Team Member
       
Group: StrataFrame Developers Last Login: Today @ 9:06:04 AM Posts: 43, Visits: 189 |
| | 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 |
| | | | 
StrataFrame User
       
Group: StrataFrame Users Last Login: Today @ 11:54:11 AM Posts: 321, Visits: 14,737 |
| 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 ) |
| | | | StrataFrame VIP
       
Group: StrataFrame Users Last Login: Today @ 12:36:01 PM Posts: 1,396, Visits: 7,912 |
| 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.
|
| | | | StrataFrame Novice
       
Group: StrataFrame Users Last Login: Today @ 11:39:09 AM Posts: 102, Visits: 2,340 |
| | Hi Les, glad to see you here! |
| |
|
|