﻿<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>StrataFrame Forum » StrataFrame Application Framework - V1 » WinForms (How do I?)  » Count of BO is Zero(0)</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Tue, 26 May 2026 00:35:08 GMT</lastBuildDate><ttl>20</ttl><item><title>Count of BO is Zero(0)</title><link>http://forum.strataframe.net/FindPost21810.aspx</link><description>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&amp;nbsp;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.</description><pubDate>Mon, 09 Feb 2009 11:33:23 GMT</pubDate><dc:creator>Terry Bottorff</dc:creator></item><item><title>RE: Count of BO is Zero(0)</title><link>http://forum.strataframe.net/FindPost21884.aspx</link><description>Great! Glad that helped!</description><pubDate>Mon, 09 Feb 2009 11:33:23 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: Count of BO is Zero(0)</title><link>http://forum.strataframe.net/FindPost21874.aspx</link><description>That worked perfect. Thank you so much.</description><pubDate>Sat, 07 Feb 2009 08:03:03 GMT</pubDate><dc:creator>Terry Bottorff</dc:creator></item><item><title>RE: Count of BO is Zero(0)</title><link>http://forum.strataframe.net/FindPost21844.aspx</link><description>I think the only way this occurs is if the BO is on a SF StandardForm. The form handles the delete message.  There is a property to turn this off on the form. See this post:&lt;br&gt;
&lt;br&gt;
[url]http://forum.strataframe.net/FindPost11030.aspx[/url]&lt;br&gt;
&lt;br&gt;
The form handles this for any BO that is in its BO collection. I believe if you do this via code only (i.e. instantiate the BO in code), there will be no messages.</description><pubDate>Thu, 05 Feb 2009 14:06:08 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: Count of BO is Zero(0)</title><link>http://forum.strataframe.net/FindPost21842.aspx</link><description>Greg&amp;nbsp;thank you so much. I sort of had the right idea but The Order I did things Sucked. But what you gave me made sense and worked great.&lt;/P&gt;&lt;P&gt;One last question on this. Is there a way to keep from having to answer yes every time you deletecurrentrow?</description><pubDate>Thu, 05 Feb 2009 13:54:35 GMT</pubDate><dc:creator>Terry Bottorff</dc:creator></item><item><title>RE: Count of BO is Zero(0)</title><link>http://forum.strataframe.net/FindPost21839.aspx</link><description>Terry,&lt;br&gt;
&lt;br&gt;
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.&lt;br&gt;
&lt;br&gt;
First, this paradigm really isn't going to do anything:&lt;br&gt;
&lt;br&gt;
[codesnippet]SwStockBO1.Clear()&lt;br&gt;
SwStockBO1.Save()[/codesnippet]&lt;br&gt;
&lt;br&gt;
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.&lt;br&gt;
&lt;br&gt;
Because of this, the first part of your code never does [b]anything[/b] in the database, thus the second part (were you add the new rows) fails, because those first four records are never deleted.&lt;br&gt;
&lt;br&gt;
So, for the first part if you did something like:&lt;br&gt;
&lt;br&gt;
[codesnippet]MessageBox.Show(SwStockBO1.Count.ToString, "Number in Stock BO")&lt;br&gt;
Dim narray(4) As Integer&lt;br&gt;
SwStockBO1.MoveFirst()&lt;br&gt;
For i = 0 To 4&lt;br&gt;
&amp;nbsp;&amp;nbsp;narray(i) = SwStockBO1.stock&lt;br&gt;
&amp;nbsp;&amp;nbsp;SwStockBO1.DeleteCurrentRow(True)&lt;br&gt;
&amp;nbsp;&amp;nbsp;SwStockBO1.MoveNext()&lt;br&gt;
Next&lt;br&gt;
MessageBox.Show(SwStockBO1.Count.ToString, "Number in Stock BO")&lt;br&gt;
SwStockBO1.Save()[/codesnippet] &lt;br&gt;
&lt;br&gt;
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). &lt;br&gt;
&lt;br&gt;
If you just want to loop through the entire BO and delete every thing, you could also do:&lt;br&gt;
&lt;br&gt;
[codesnippet]MessageBox.Show(SwStockBO1.Count.ToString, "Number in Stock BO")&lt;br&gt;
Dim narray() As Integer&lt;br&gt;
Dim stockCount As Integer = SwStockBO1.Count&lt;br&gt;
Redim narray(stockCount -1)&lt;br&gt;
SwStockBO1.MoveFirst()&lt;br&gt;
For i As Integer = 0 To stockCount -1&lt;br&gt;
&amp;nbsp;&amp;nbsp;narray(i) = SwStockBO1.stock&lt;br&gt;
&amp;nbsp;&amp;nbsp;SwStockBO1.DeleteCurrentRow(True)&lt;br&gt;
&amp;nbsp;&amp;nbsp;SwStockBO1.MoveNext()&lt;br&gt;
Next&lt;br&gt;
' This will report number of records in BO (nothing removed yet)&lt;br&gt;
MessageBox.Show(SwStockBO1.Count.ToString, "Number in Stock BO")&lt;br&gt;
SwStockBO1.Save()&lt;br&gt;
' After save, the BO will be empty and count should be zero&lt;br&gt;
MessageBox.Show(SwStockBO1.Count.ToString, "Number in Stock BO")[/codesnippet]&lt;br&gt;
&lt;br&gt;
Here I'm just using the count of the BO to drive the size of the array and the loop.&lt;br&gt;
&lt;br&gt;
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!&lt;br&gt;
&lt;br&gt;</description><pubDate>Thu, 05 Feb 2009 11:44:08 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: Count of BO is Zero(0)</title><link>http://forum.strataframe.net/FindPost21837.aspx</link><description>[codesnippet]&lt;FONT size=2&gt;&lt;P&gt;MessageBox.Show(SwStockBO1.Count.ToString, &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;"Number in Stock"&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;)&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;Dim&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; narray(4) &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;Integer&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;SwStockBO1.MoveFirst()&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;For&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; i = 0 &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;To&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; 4&lt;/P&gt;&lt;P&gt;narray(i) = SwStockBO1.stock&lt;/P&gt;&lt;P&gt;SwStockBO1.MoveNext()&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;Next&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;SwStockBO1.Clear()&lt;/P&gt;&lt;P&gt;MessageBox.Show(SwStockBO1.Count.ToString, &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;"Number in&amp;nbsp;Stock"&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;)&lt;/P&gt;&lt;P&gt;SwStockBO1.Save()&lt;/P&gt;&lt;P&gt;narray(2) = 0&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;Dim&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; ncnt &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;Integer&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; = 1&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;For&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; i = 0 &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;To&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; 4&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;If&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; narray(i) &amp;lt;&amp;gt; 0 &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;Then&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;SwStockBO1.NewRow()&lt;/P&gt;&lt;P&gt;SwStockBO1.swst_pk = ncnt&lt;/P&gt;&lt;P&gt;SwStockBO1.stock = narray(i)&lt;/P&gt;&lt;P&gt;ncnt += 1&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;End&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;If&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;Next&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;MessageBox.Show(SwStockBO1.Count.ToString, &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;&lt;FONT color=#a31515 size=2&gt;"Number in&amp;nbsp;Stock"&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;)&lt;/P&gt;&lt;P&gt;SwStockBO1.Save()&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;[/codesnippet]&lt;/P&gt;&lt;P&gt;The first messagebox indiates 5 records which is what is there, the second indicates 0 which is what I would suspect and the third is 4 which is what I want.&lt;/P&gt;&lt;P&gt;Alright Alex, Edhy and Greg what am I missing here? Why when the above code in the simple Click of a Button is executed don't I get 4 records in the table instead of an error saying can not have duplicate Primary Keys. I am doing my own primary key right now. Even if I change the primary key to one that is not found in the table I then get 9 records instead of the 4 I want.&lt;P&gt;Do I need a SStockBO1.DeleteCurrentRow() instead of just a clear and save? Well I inserted this code &lt;P&gt;[codesnippet]&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;Do&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;While&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt; SwStockBO1.Count &amp;gt; 0&lt;/P&gt;&lt;P&gt;SwStockBO1.DeleteCurrentRow()&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;Loop&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;/FONT&gt;[/codesnippet]&lt;P&gt;and of course it asked me about deleting each record(which I can not have in real life because there would be too many records) but I still get the same result? TIA</description><pubDate>Thu, 05 Feb 2009 10:30:54 GMT</pubDate><dc:creator>Terry Bottorff</dc:creator></item><item><title>RE: Count of BO is Zero(0)</title><link>http://forum.strataframe.net/FindPost21822.aspx</link><description>Terry,&lt;br&gt;
&lt;br&gt;
I'm not sure if this will help, but the BO is disconnected from the data. Thus, when you fill it, you lookup data in the db and load it into the BO. Once that is done, the BO isn't talking to the db any longer (until the BO needs to talk to it again, for another fill, to save or delete data).  Thus, the Clear() method of the BO simply clears any data that was loaded into it, which has NO effect on the actual data (it's disconnected from it).  This is great if you need to "smoke" (a bit of Texan vocabulary I picked up from Trent) the data in the BO in order to load another set of data into it. &lt;br&gt;
&lt;br&gt;
However, if what you want is to actually delete data from the db, you need to go about it a bit differently. There are a couple of possibilities, depending on what you want to do.&lt;br&gt;
&lt;br&gt;
First, if you already have the data loaded into the BO and you want to delete some or all of that data, you would add a method to the BO to loop through the rows of the BO and call Delete() on each row you want to delete. You would use a For loop and use the .Count property of the BO. Probably the most efficient way is to mark the rows for deletion and then do a Save() to actually delete them.  &lt;br&gt;
&lt;br&gt;
The second way is if you just need to delete a set of rows based on some criterion, like smokin all the records older than a certain date. In this case you would write a method in the BO that would accept the necessary parameters and either build some SQL or call a sproc to just execute a DELETE statement in the database.&lt;br&gt;
&lt;br&gt;
I hope that clears up what some of your options might be in order to delete data in the db vs. clearing loaded data from a BO.</description><pubDate>Wed, 04 Feb 2009 10:29:14 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: Count of BO is Zero(0)</title><link>http://forum.strataframe.net/FindPost21821.aspx</link><description>Hi Terry, &lt;P&gt;There must be something in the way you are checking the BO count.&amp;nbsp; Do the following test:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Fill your BO with some records&lt;/LI&gt;&lt;LI&gt;Test your BO.Count it should have the amount of records you filled with.&lt;/LI&gt;&lt;LI&gt;Them do a BO.Clear, it should reset the BO.Count = 0&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;[quote]The pk's are automatically generated. I know I used 8 and 100, how do I write the remaining stock back? TIA. [/quote]&lt;/P&gt;&lt;P&gt;If I understand you correctly, you could have several records in your BO and out of those you just want to save a couple, if this is right, you can do this several ways:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Have a flag field which will allow you to filter out the records you want to save, then use the BO.Filter = "MyFlagField = True" or something along those lines.&lt;/LI&gt;&lt;LI&gt;Or you can iterate through all the BO records, copy the ones you want to save into another BO, then save the other BO.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;If that was not what you meant, please let us know.</description><pubDate>Wed, 04 Feb 2009 09:59:49 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item><item><title>RE: Count of BO is Zero(0)</title><link>http://forum.strataframe.net/FindPost21818.aspx</link><description>These statements did not get rid of the 100 original records in the table.&lt;P&gt;[codesnippet]&lt;/P&gt;&lt;P&gt;Bo.clear()&lt;/P&gt;&lt;P&gt;Bo.Save()&lt;/P&gt;&lt;P&gt;[/codesnippet]&lt;/P&gt;&lt;P&gt;I think&amp;nbsp;there must be a way to get rid of the original 100 records with out an iteration thru the records but I have not found it yet. Thanks.&lt;/P&gt;&lt;P&gt;While I am here lets say Table&amp;nbsp;A has the following Records(pk=primary key):&lt;/P&gt;&lt;P&gt;pk=1 stock=5&lt;/P&gt;&lt;P&gt;pk=2 stock=8&lt;/P&gt;&lt;P&gt;pk=3 stock=100&lt;/P&gt;&lt;P&gt;pk=4 stock=200&lt;/P&gt;&lt;P&gt;Suppose we use 8 and 100 and I want to write the remaining stock back to the table so the table contains:&lt;/P&gt;&lt;P&gt;pk=5 stock=5&lt;/P&gt;&lt;P&gt;pk=6 stock=200&lt;/P&gt;&lt;P&gt;The pk's are automagically generated. I know I used 8 and 100, how do I write the remaining stock back? TIA.</description><pubDate>Wed, 04 Feb 2009 09:30:54 GMT</pubDate><dc:creator>Terry Bottorff</dc:creator></item><item><title>RE: Count of BO is Zero(0)</title><link>http://forum.strataframe.net/FindPost21817.aspx</link><description>Hi Alex,&lt;P&gt;Thanks for the kind comments, I also learned a lot from others here and continue to do so everyday.&lt;/P&gt;&lt;P&gt;[Quote]Wouldn't the .Clear( ) only operate on the rows the BO retrieved?[/Quote]&lt;BR&gt;&lt;/P&gt;&lt;P&gt;Yes, basically based on the comment in the SF source code, the BO.Clear method will do reset the data table with no records.&lt;/P&gt;&lt;P&gt;[quote]&lt;FONT size=2&gt;&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&lt;FONT color=#008000 size=2&gt;''' Clears all data in the business object and sets the current data table back to its initial state&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&lt;FONT color=#008000 size=2&gt;''' with all columns belonging to the table schema&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;/FONT&gt;[/quote]</description><pubDate>Wed, 04 Feb 2009 08:29:29 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item><item><title>RE: Count of BO is Zero(0)</title><link>http://forum.strataframe.net/FindPost21815.aspx</link><description>[quote]I believe BO.Clear will do the trick.[/quote]&lt;br&gt;
&lt;br&gt;
Hi Edhy -&lt;br&gt;
&lt;br&gt;
Good Morning! I've learned a lot from your postings, so I thought I'd say Thanks while I am here. :) &lt;br&gt;
&lt;br&gt;
Wouldn't the .Clear( ) only operate on the rows the BO retrieved?&lt;br&gt;
&lt;br&gt;
________________&lt;br&gt;
_____/ Regards,   &lt;br&gt;
____/ al      &lt;br&gt;
&lt;br&gt;</description><pubDate>Wed, 04 Feb 2009 07:57:02 GMT</pubDate><dc:creator>Alex Luyando</dc:creator></item><item><title>RE: Count of BO is Zero(0)</title><link>http://forum.strataframe.net/FindPost21814.aspx</link><description>Terry -&lt;br&gt;
&lt;br&gt;
I am a relative newbie as well, so take this with a grain of salt. The BO's functionality would be limited to the data it has in it's datastore. As there were no records retrieved as a result of your Fill() the "other" rows (the 100 in the table on the backend) would not be affected by anything you do with the BO's data. &lt;br&gt;
&lt;br&gt;
HTH&lt;br&gt;
&lt;br&gt;
________________&lt;br&gt;
_____/ Regards,   &lt;br&gt;
____/ al      &lt;br&gt;
&lt;br&gt;</description><pubDate>Wed, 04 Feb 2009 07:53:03 GMT</pubDate><dc:creator>Alex Luyando</dc:creator></item><item><title>RE: Count of BO is Zero(0)</title><link>http://forum.strataframe.net/FindPost21812.aspx</link><description>[quote][b]Terry Bottorff (02/04/2009)[/b][hr]... if I really want to remove all of the previous records in the table what is the quickest way?[/quote]&lt;P&gt;Hi Terry,&lt;/P&gt;&lt;P&gt;I believe BO.Clear will do the trick.</description><pubDate>Wed, 04 Feb 2009 07:49:29 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item></channel></rss>