Count of BO is Zero(0)


Author
Message
Terry Bottorff
Terry Bottorff
StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)
Group: Forum Members
Posts: 448, Visits: 12K
I'm a newbie and trying to get my head around all of this. If I do a fill on a BO like the Following:" Select * from stock where 1 = 2" and do a BO.Count it is obviously 0 even though the table has 100 records. That is OK but why when I do BO.Save() does all of the records remain? I think it has to do with no changes in BO but if I really want to remove all of the previous records in the table what is the quickest way? No relationships to worry about just a table that hold previous data and now needs to get all new data???? TIA.
Reply
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (4.8K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Terry,



Not sure I'm following your logic, so it is hard to offer detailed help. However, maybe I can offer some bits of help that will keep you moving.



First, this paradigm really isn't going to do anything:



SwStockBO1.Clear()

SwStockBO1.Save()




Nothing will ever get saved. And if there were changes in the SwStockBO1, they'd be lost. Clear() removes all the rows in the underlying DataTable. Those rows drive if there is anything to save or not. A DataRow has a row state that indicates if it is dirty and how it is dirty (new, edited, deleted). When a Save() happens, it walks the rows and either adds, updates or deletes the rows. No rows to walk, nothing to do.



Because of this, the first part of your code never does anything in the database, thus the second part (were you add the new rows) fails, because those first four records are never deleted.



So, for the first part if you did something like:



MessageBox.Show(SwStockBO1.Count.ToString, "Number in Stock BO")

Dim narray(4) As Integer

SwStockBO1.MoveFirst()

For i = 0 To 4

  narray(i) = SwStockBO1.stock

  SwStockBO1.DeleteCurrentRow(True)

  SwStockBO1.MoveNext()

Next

MessageBox.Show(SwStockBO1.Count.ToString, "Number in Stock BO")

SwStockBO1.Save()




You'd walk the first four rows of the BO, cache the "stock" value in your narray, mark those four rows for deletion, then actually delete those rows from the database when Save is called (and they'd be removed from the BO then as well).



If you just want to loop through the entire BO and delete every thing, you could also do:



MessageBox.Show(SwStockBO1.Count.ToString, "Number in Stock BO")

Dim narray() As Integer

Dim stockCount As Integer = SwStockBO1.Count

Redim narray(stockCount -1)

SwStockBO1.MoveFirst()

For i As Integer = 0 To stockCount -1

  narray(i) = SwStockBO1.stock

  SwStockBO1.DeleteCurrentRow(True)

  SwStockBO1.MoveNext()

Next

' This will report number of records in BO (nothing removed yet)

MessageBox.Show(SwStockBO1.Count.ToString, "Number in Stock BO")

SwStockBO1.Save()

' After save, the BO will be empty and count should be zero

MessageBox.Show(SwStockBO1.Count.ToString, "Number in Stock BO")




Here I'm just using the count of the BO to drive the size of the array and the loop.



I just typed this in, so there might be some errors, but hopefully it helps you understand what is going on and gets you moving! Good luck!



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