﻿<?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 » Business Objects and Data Access (How do I?)  » Generate sequencial number in a BO</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Thu, 30 Apr 2026 21:02:38 GMT</lastBuildDate><ttl>20</ttl><item><title>Generate sequencial number in a BO</title><link>http://forum.strataframe.net/FindPost15035.aspx</link><description>Hi All, &lt;P&gt;I have several form which will show a list with a sequential order number like 1,2,3,4, etc.&amp;nbsp; (See picture below).&amp;nbsp; I want this field LineOrder to be autogenerated with the next unused value when a new record is created, so if the last one used is 5, then when clicking New, the value will be 6.&lt;/P&gt;&lt;P&gt;&lt;IMG src="http://forum.strataframe.net/Uploads/Images/173d8a64-48fa-47ae-8bd8-15a6.png"&gt;&lt;/P&gt;&lt;P&gt;I added the following code in the PaymentMethodBO.vb:&lt;/P&gt;&lt;P&gt;[codesnippet]&lt;FONT size=2&gt;&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Private&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Sub&lt;/FONT&gt;&lt;FONT size=2&gt; PaymentMethod_SetDefaultValues()&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' --- Calculate the next LineOrder number to be added as a default value for Me.LineOrder field.&lt;/P&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=#008000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;Me&lt;/FONT&gt;&lt;FONT size=2&gt;.MoveLast() &lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;' This will move the record pointer to the last record, in this case the new one.&lt;/P&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=#008000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;Me&lt;/FONT&gt;&lt;FONT size=2&gt;.MovePrevious() &lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;' Go back to the previous record which should be the last one.&lt;/P&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=#008000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;Dim&lt;/FONT&gt;&lt;FONT size=2&gt; nextLineOrder &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Integer&lt;/FONT&gt;&lt;FONT size=2&gt; = 0&lt;/P&gt;&lt;P&gt;&lt;FONT color=#008000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;nextLineOrder = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Me&lt;/FONT&gt;&lt;FONT size=2&gt;.LineOrder + 1 &lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;' Increment 1 to get the next default value.&lt;/P&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=#008000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;If&lt;/FONT&gt;&lt;FONT size=2&gt; nextLineOrder = 0 &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Then&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;FONT color=#008000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;nextLineOrder = 1&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#008000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;End&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;If&lt;/P&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=#008000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;Me&lt;/FONT&gt;&lt;FONT size=2&gt;.MoveLast() &lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;' Go back to the new record&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' Set the default Value here&lt;/P&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=#008000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;Me&lt;/FONT&gt;&lt;FONT size=2&gt;.LineOrder = nextLineOrder&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;End&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Sub&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;[/codesnippet]&lt;/P&gt;&lt;P&gt;So far this is working fine, but I would like to make sure this is the proper way to get this done when working with data in the BO.&amp;nbsp; I&amp;nbsp;guess I may have another BO with a SELECT MAX() statement to get the last value used and then increment this value.&amp;nbsp; So I would appreciate any recommendation in this regard.&lt;/P&gt;&lt;P&gt;Thanks!:)</description><pubDate>Mon, 03 Nov 2008 13:33:51 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item><item><title>RE: Generate sequencial number in a BO</title><link>http://forum.strataframe.net/FindPost20526.aspx</link><description>Yeah, I noticed the same thing... *scratching head*&amp;nbsp;:D&amp;nbsp; I don't have a lot of time to dedicate to this at the moment, but I know that it is possible, so I will have to add this to the "to-look-at" list.</description><pubDate>Mon, 03 Nov 2008 13:33:51 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: Generate sequencial number in a BO</title><link>http://forum.strataframe.net/FindPost20524.aspx</link><description>Er...I mean one of Trent's other suggestions...can't see straight this morning apparently..</description><pubDate>Mon, 03 Nov 2008 13:03:53 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: Generate sequencial number in a BO</title><link>http://forum.strataframe.net/FindPost20523.aspx</link><description>Well, I would have sworn Trent was right on this one. But I just attempted to do this via scripts and it reported that only one identity column is allowed per table.  I'd use one of Edhy's suggestions.</description><pubDate>Mon, 03 Nov 2008 13:02:53 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: Generate sequencial number in a BO</title><link>http://forum.strataframe.net/FindPost20517.aspx</link><description>Here would be my suggestion.&amp;nbsp; Instead of fighting all of that, just create a sproc and either create an INSERT trigger or set the default value to pull from where ever you need to populate that transation unique ID.&amp;nbsp; You could have unique ID table that has the name of the table and the next value that you pull from or if you just want to execute another query from the same table and get the MAX value of the current column and increment it by one, you could do that as well.&amp;nbsp; Another option would be to do this at the BO level in the SetDefaultValues event.&amp;nbsp; Just call a scalar method that does the same thing that the trigger I was talking about would do.&amp;nbsp; You have a number of options here.</description><pubDate>Mon, 03 Nov 2008 10:49:43 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: Generate sequencial number in a BO</title><link>http://forum.strataframe.net/FindPost20516.aspx</link><description>Hi Trent,&lt;BR&gt;&lt;BR&gt;Thanks for your reply and please see this small video of what I tried to do regarding the transactionNo field. That field will be an Invoice Number like 1 , 2, 35 etc... and must be unique the same way as a PK field.&lt;P&gt;&lt;A href="http://www.dfarber.com/Counter.rar"&gt;http://www.dfarber.com/Counter.rar&lt;/A&gt; (it is 1.7 mb)&lt;BR&gt;and Video worth a thousands words.:)&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Doron&lt;BR&gt;&lt;BR&gt;</description><pubDate>Mon, 03 Nov 2008 10:28:10 GMT</pubDate><dc:creator>Doron Farber</dc:creator></item><item><title>RE: Generate sequencial number in a BO</title><link>http://forum.strataframe.net/FindPost20501.aspx</link><description>No.&amp;nbsp; Actually you can do the very same thing through SSMS (SQL Server Management Studio) or if you create your tables using a script.&amp;nbsp; This is just standard SQL Server functionality.&amp;nbsp; You are welcome to post your error or take a screen shot of how you are setting up the database.&amp;nbsp; I just used the DDT for the screen shots, but it creates this as part of the standard SQL Server table when deployed.&amp;nbsp; This is not done via a sproc.&lt;/P&gt;&lt;P&gt;In SQL Server, this is called an identity column.&amp;nbsp; You can technically setup as many of these as you need.&amp;nbsp; If you modify a table through SSMS, you can go down to the Identity section, and specify an auto-increment seed, etc.</description><pubDate>Sat, 01 Nov 2008 10:25:15 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: Generate sequencial number in a BO</title><link>http://forum.strataframe.net/FindPost20488.aspx</link><description>Hi Trent,&lt;P&gt;Thanks for your reply. Yes I see that you can have the second Auto Increment&amp;nbsp;using the DDT package which I also&amp;nbsp;tried to do&amp;nbsp;and see below image. Right now I am&amp;nbsp; NOT using yet the DDT package and I tried to create the second auto increment in the actual ms sql 2005&amp;nbsp;table.&amp;nbsp;As far as I know it can not be accomplished unless&amp;nbsp;you use a Stored Procedure. I assune&amp;nbsp;the DDT also created a Stored&amp;nbsp;Procedure for this purpose.&lt;/P&gt;&lt;P&gt;Thanks,&lt;BR&gt;&lt;BR&gt;Doron</description><pubDate>Fri, 31 Oct 2008 13:11:21 GMT</pubDate><dc:creator>Doron Farber</dc:creator></item><item><title>RE: Generate sequencial number in a BO</title><link>http://forum.strataframe.net/FindPost20438.aspx</link><description>Here is a primary key column with an identity (auto-increment) defined:&lt;/P&gt;&lt;P&gt;&lt;IMG src="http://forum.strataframe.net/Uploads/Images/f57e2b9c-1326-4003-8420-b7b1.png"&gt;&lt;/P&gt;&lt;P&gt;Then here is a column with just the identity )aut-incrementing) column defined:&lt;/P&gt;&lt;P&gt;&lt;IMG src="http://forum.strataframe.net/Uploads/Images/f825a99e-ea74-4192-9603-7fc6.png"&gt;&lt;/P&gt;&lt;P&gt;These are both in the same table and will both automatically generate a new value when a new row is created using the identity column (auto-incrementing) settings.&amp;nbsp; I have also attached these images for a better view.</description><pubDate>Thu, 30 Oct 2008 09:32:09 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: Generate sequencial number in a BO</title><link>http://forum.strataframe.net/FindPost20412.aspx</link><description>Ok Trent,&lt;BR&gt;&lt;BR&gt;But when I change the Identity to Yes in the TransactionNo field then the PK field is lossing its Identity and it turns to No or visa versa. &lt;BR&gt;&lt;BR&gt;So that does not work for me unless you can be more specific and maybe through me a screen shot. I need to keep the Identity of the PK all the time.&lt;BR&gt;&lt;BR&gt;Thanks,&lt;BR&gt;&lt;BR&gt;Doron</description><pubDate>Wed, 29 Oct 2008 11:37:58 GMT</pubDate><dc:creator>Doron Farber</dc:creator></item><item><title>RE: Generate sequencial number in a BO</title><link>http://forum.strataframe.net/FindPost20410.aspx</link><description>Sure you can ;)&amp;nbsp; You can have as many identity columns as you would like.&amp;nbsp; It doesn't need to be a PK, just an identity column that is auto-incrementing.</description><pubDate>Wed, 29 Oct 2008 11:30:05 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: Generate sequencial number in a BO</title><link>http://forum.strataframe.net/FindPost20409.aspx</link><description>Hi Trent,&lt;P&gt;But I have already&amp;nbsp;PK field that is an Auto Increment, and you cannot have 2 fields like that in the same table. I tried that and did not work:)&lt;P&gt;I think another solution like a generic class that you use in your medical application could be very helpfull these days. When I used the VFP framework like the ProMatrix&amp;nbsp;one,&amp;nbsp;that was a given.:hehe:&lt;P&gt;That will be nice to see something like that in the next update...:cool:&lt;P&gt;More features more sales...&lt;P&gt;Thanks,&lt;P&gt;Doron</description><pubDate>Wed, 29 Oct 2008 10:54:58 GMT</pubDate><dc:creator>Doron Farber</dc:creator></item><item><title>RE: Generate sequencial number in a BO</title><link>http://forum.strataframe.net/FindPost20403.aspx</link><description>If you want SQL Server to generate it, just create the column as auto-incrementing and provide the seed just as you would for an auto-incrementing PK.&amp;nbsp; In this case, you would just &lt;STRONG&gt;&lt;EM&gt;&lt;U&gt;not&lt;/U&gt;&lt;/EM&gt;&lt;/STRONG&gt; make it a PK field.</description><pubDate>Tue, 28 Oct 2008 20:42:01 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: Generate sequencial number in a BO</title><link>http://forum.strataframe.net/FindPost20401.aspx</link><description>Hi Trent,&lt;P&gt;Regarding an Invoice ID which is a unique number and how would you really create that in the ms sql 2005? You are allowed just one counter per table. In the last training we had a discussion about a class that will be created in some point. But maybe there is a direct way to implement that in the sql server level.&amp;nbsp; &lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Doron&lt;BR&gt;</description><pubDate>Tue, 28 Oct 2008 18:19:14 GMT</pubDate><dc:creator>Doron Farber</dc:creator></item><item><title>RE: Generate sequencial number in a BO</title><link>http://forum.strataframe.net/FindPost15071.aspx</link><description>[quote] I don't know if with SQL2005 you can have as many AutoIncrement fields as you want[/quote]&lt;/P&gt;&lt;P&gt;You can have as many as you need and this is the recommended way to do things and is what we do.&amp;nbsp; However, if you need the old style of NextId, then you can do that too :)</description><pubDate>Thu, 20 Mar 2008 13:07:31 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: Generate sequencial number in a BO</title><link>http://forum.strataframe.net/FindPost15070.aspx</link><description>Hi Trent, &lt;P&gt;For now these tables will be used initially in the application to setup some lookup values, so I am pretty sure only the Admin will have access to those forms, but I will enhance it to use an old fashioned NextID routine since there are a couple of those I need for Cash Receipt and Invoice.&amp;nbsp; I don't know if with SQL2005 you can have as many AutoIncrement fields as you want, but if not then a NextID routine will be needed to handle those numbers. &lt;P&gt;Thanks for the tip on MyBo.MoveAbsolute I'll keep it in mind since there are some data manipulations I need to do in this project but have not get there yet, so be ready for my questions :D</description><pubDate>Thu, 20 Mar 2008 12:08:54 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item><item><title>RE: Generate sequencial number in a BO</title><link>http://forum.strataframe.net/FindPost15062.aspx</link><description>Looks good...as long as you don't plan on two people hitting this table at the same time, then you could have an issue.&amp;nbsp; If you do not want to allow an auto-incrementing field to do this for you, then I would recommend creating a good ol' fashioned NextId table that is incremented with every query, this way if you have two, ten, or a hundred people hit this at the same time you will not have an overlapping of values.&amp;nbsp; Otherwise, your code really does look good.&amp;nbsp; The only thing I might mention would be the code you posted initially.&amp;nbsp; You were using MoveLast and the MovePrior.&amp;nbsp; You can do that, but you could do this in one line instead of two or three:&lt;/P&gt;&lt;P&gt;[codesnippet]MyBo.MoveAbsolute(MyBo.Count-2)[/codesnippet]&lt;/P&gt;&lt;P&gt;But keep up the good work...it looks good! :)</description><pubDate>Thu, 20 Mar 2008 09:48:03 GMT</pubDate><dc:creator>Trent L. Taylor</dc:creator></item><item><title>RE: Generate sequencial number in a BO</title><link>http://forum.strataframe.net/FindPost15051.aspx</link><description>Looking good Edhy!&lt;br&gt;
&lt;br&gt;
The FieldNames is an enum that is defined within the designer file of the BO. If you look in the Object Browser, find you BO, the next object in the list will be the BO.  If the BO is named MyBO, then right after it will be an enum named MyBOFieldNames. If the BO is named YourBO, then right after it will be an enum named YourBOFieldNames.  &lt;br&gt;
&lt;br&gt;
I don't believe you can get the field name from the strongly typed property itself (i.e. you can't get the field name from Me.LineOrder).  &lt;br&gt;
&lt;br&gt;
Glad you're getting it going!</description><pubDate>Thu, 20 Mar 2008 00:45:23 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: Generate sequencial number in a BO</title><link>http://forum.strataframe.net/FindPost15050.aspx</link><description>[quote][b]Greg McGuffey (03/19/2008)[/b][hr]&lt;P&gt;- When the BO is created there is an enum created that provides access to all the field names. It will be within the BO and have a name like MyBO.MyBOFieldNames. You could then just use the ToString() on the field (you'd replace MyBO with the actual name of your BO). I'm not sure this helps, but it does provide a strongly typed access to field names, so if you change the name, code won't compile and you can find the problem quicker:&lt;BR&gt;[codesnippet]String.Format("SELECT Top 1 [{0}] + 1 FROM {1} Order By [{0}] DESC", MyBO.MyBoFieldNames.LineOrderFieldName.ToString(), Me.TableName)[/codesnippet]&lt;BR&gt;[/quote]&lt;/P&gt;&lt;P&gt;Hi Greg,&lt;/P&gt;&lt;P&gt;You definitely get me going :P&lt;/P&gt;&lt;P&gt;I made some modifications and&amp;nbsp;checked the return value to foolproof the function.&amp;nbsp; I tested with a blank table and it worked perfectly.&amp;nbsp; I stick with the MAX() for simplicity, anyway those tables will not have many records anyway and they are properly indexed.&amp;nbsp; Here the new version:&lt;/P&gt;&lt;P&gt;[codesnippet]&lt;FONT size=2&gt;&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Private&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Function&lt;/FONT&gt;&lt;FONT size=2&gt; GetNextLineOrder(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;ByVal&lt;/FONT&gt;&lt;FONT size=2&gt; LineOrderFieldName &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;String&lt;/FONT&gt;&lt;FONT size=2&gt;, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;ByVal&lt;/FONT&gt;&lt;FONT size=2&gt; TableName &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;String&lt;/FONT&gt;&lt;FONT size=2&gt;) &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Integer&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim&lt;/FONT&gt;&lt;FONT size=2&gt; sqlStringCommand &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;String&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;sqlStringCommand = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;String&lt;/FONT&gt;&lt;FONT size=2&gt;.Format(&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"SELECT MAX( {0} ) + 1 FROM {1}"&lt;/FONT&gt;&lt;FONT size=2&gt;, LineOrderFieldName, TableName)&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;' --- Test the returned result for DBNull value and if so return 1.&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dim&lt;/FONT&gt;&lt;FONT size=2&gt; loValue &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Object&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;FONT color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;loValue = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Me&lt;/FONT&gt;&lt;FONT size=2&gt;.ExecuteScalar(sqlStringCommand)&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; If&lt;/FONT&gt;&lt;FONT size=2&gt; loValue &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Is&lt;/FONT&gt;&lt;FONT size=2&gt; DBNull.Value &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Then&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Else&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Return&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;CType&lt;/FONT&gt;&lt;FONT size=2&gt;(loValue, System.Int16)&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; End&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;If&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;End&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Function&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;[/codesnippet]&lt;/P&gt;&lt;P&gt;Of course I cheated a bit with the loValue code above which I copied from the BO designer file. :cool:&lt;/P&gt;&lt;P&gt;For the Field Enums I only found a property &lt;FONT color=#0000ff size=2&gt;&lt;FONT color=#0000ff size=2&gt;Me&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;.FieldEnums and frankly I could not found a way to use it to return the field name, but in this case it may no be necessary since the field name is the same in all tables "LineOrder",&lt;STRONG&gt;&lt;EM&gt; but it will be good to know how to get the field name from the field object &lt;FONT color=#0000ff size=2&gt;Me&lt;/FONT&gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;FONT size=2&gt;&lt;STRONG&gt;&lt;EM&gt;.LineOrder&lt;/EM&gt;&lt;/STRONG&gt;.&lt;/P&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT color=#000000&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;P&gt;Thanks again!</description><pubDate>Wed, 19 Mar 2008 21:31:54 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item><item><title>RE: Generate sequencial number in a BO</title><link>http://forum.strataframe.net/FindPost15047.aspx</link><description>I might make a couple of suggestions:&lt;br&gt;
&lt;br&gt;
- You don't need to use the ToString() on LineOrderFieldName or TableName. They are already a strings ;)&lt;br&gt;
- Another way to get the same result as using the MAX function, is to use sorting and the top directive. I'm not sure which is faster, assuming that the LineOrderFieldName is indexed, but thought I'd throw out another idea. I.e. you sql would be something like:&lt;br&gt;
[codesnippet]"SELECT Top 1 (" &amp; LineOrderFieldName &amp; ") + 1 FROM " &amp; TableName &amp; " Order By " &amp; LineOrderFieldName &amp; " DESC"[/codesnippet]&lt;br&gt;
- Use String.Format. It's a good habit to get into and it deals with strings more efficiently, as I recall. So now you might do the SQL String like:&lt;br&gt;
[codesnippet]String.Format("SELECT Top 1 [{0}] + 1 FROM {1} Order By [{0}] DESC", LineOrderFieldName, Me.TableName)[/codesnippet]&lt;br&gt;
- When the BO is created there is an enum created that provides access to all the field names. It will be within the BO and have a name like MyBO.MyBOFieldNames.  You could then just use the ToString() on the field (you'd replace MyBO with the actual name of your BO). I'm not sure this helps, but it does provide a strongly typed access to field names, so if you change the name, code won't compile and you can find the problem quicker:&lt;br&gt;
[codesnippet]String.Format("SELECT Top 1 [{0}] + 1 FROM {1} Order By [{0}] DESC", MyBO.MyBoFieldNames.LineOrderFieldName.ToString(), Me.TableName)[/codesnippet]&lt;br&gt;
- This will fail if there are no LineOrder records found. I.e. the Select will return NULL as there is no data yet, and NULL  + 1 is still NULL.  So, you should either check the return for NULL (DbNull.Value) in you BO method or add to the SQL to handle it.&lt;br&gt;
&lt;br&gt;
Good luck!</description><pubDate>Wed, 19 Mar 2008 20:07:22 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item><item><title>RE: Generate sequencial number in a BO</title><link>http://forum.strataframe.net/FindPost15045.aspx</link><description>Hi Greg,&lt;P&gt;I ended up creating a function "GetNextLineOrder" in the BO which will query the table for the next available number.&amp;nbsp; Please see code below.&lt;/P&gt;&lt;P&gt;Only thing I could not figure out is how to pass the FieldName as a string instead of hard coding it in the Service_SetDefaultValues in order to make the call more generic since I will be using this code in several BO's.&amp;nbsp; Again, thanks for all your advice and pointing me in the right direction.&lt;/P&gt;&lt;P&gt;[codesnippet]&lt;FONT size=2&gt;&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;''' &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;&amp;lt;summary&amp;gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;''' Sets the default values for a new row&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;''' &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;&amp;lt;/summary&amp;gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;''' &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;&amp;lt;remarks&amp;gt;&amp;lt;/remarks&amp;gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Private&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Sub&lt;/FONT&gt;&lt;FONT size=2&gt; Service_SetDefaultValues()&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;' --- Calculate the next LineOrder number to be added as a default value for Me.LineOrder field.&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Me&lt;/FONT&gt;&lt;FONT size=2&gt;.LineOrder = &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Me&lt;/FONT&gt;&lt;FONT size=2&gt;.GetNextLineOrder(&lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"LineOrder"&lt;/FONT&gt;&lt;FONT size=2&gt;, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Me&lt;/FONT&gt;&lt;FONT size=2&gt;.TableName.ToString())&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;End&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Sub&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color=#0000ff size=2&gt;&amp;nbsp;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;''' &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;&amp;lt;summary&amp;gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;''' This function will generate a query to get the next available Line Order number.&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;''' &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;&amp;lt;/summary&amp;gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;''' &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;&amp;lt;param name="LineOrderFieldName"&amp;gt;&amp;lt;/param&amp;gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;''' &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;&amp;lt;param name="TableName"&amp;gt;&amp;lt;/param&amp;gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;''' &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;&amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#008000 size=2&gt;''' &lt;/FONT&gt;&lt;FONT color=#808080 size=2&gt;&amp;lt;remarks&amp;gt;&amp;lt;/remarks&amp;gt;&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Private&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Function&lt;/FONT&gt;&lt;FONT size=2&gt; GetNextLineOrder(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;ByVal&lt;/FONT&gt;&lt;FONT size=2&gt; LineOrderFieldName &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;String&lt;/FONT&gt;&lt;FONT size=2&gt;, &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;ByVal&lt;/FONT&gt;&lt;FONT size=2&gt; TableName &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;String&lt;/FONT&gt;&lt;FONT size=2&gt;) &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Integer&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;Dim&lt;/FONT&gt;&lt;FONT size=2&gt; sqlStringCommand &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;As&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;String&lt;/P&gt;&lt;/FONT&gt;&lt;FONT size=2&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;sqlStringCommand = &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;"SELECT MAX("&lt;/FONT&gt;&lt;FONT size=2&gt; &amp;amp; LineOrderFieldName.ToString &amp;amp; &lt;/FONT&gt;&lt;FONT color=#a31515 size=2&gt;") + 1 FROM "&lt;/FONT&gt;&lt;FONT size=2&gt; &amp;amp; TableName.ToString&lt;/P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&lt;FONT size=2&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;Return&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;CType&lt;/FONT&gt;&lt;FONT size=2&gt;(&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Me&lt;/FONT&gt;&lt;FONT size=2&gt;.ExecuteScalar(sqlStringCommand), &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Integer&lt;/FONT&gt;&lt;FONT size=2&gt;)&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;End&lt;/FONT&gt;&lt;FONT size=2&gt; &lt;/FONT&gt;&lt;FONT color=#0000ff size=2&gt;Function&lt;/P&gt;&lt;P&gt;&lt;/FONT&gt;[/codesnippet]&lt;P&gt;P.S.&lt;P&gt;I will add some TRY...ENDTRY error validation in case something happend in two months :w00t:</description><pubDate>Wed, 19 Mar 2008 19:28:12 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item><item><title>RE: Generate sequencial number in a BO</title><link>http://forum.strataframe.net/FindPost15043.aspx</link><description>Hi Greg,&lt;/P&gt;&lt;P&gt;This kind of data will be usually in use by a single user, since it is just the Line order for the records that will be shown as a lookup in a combo, so these forms will not be use by multiple users.&amp;nbsp; That's why I used the data in the BO to get the last one used, even though I think a better approach is to use the database with a view or SP to get the MAX() + 1.&lt;/P&gt;&lt;P&gt;Thanks for the explanation.</description><pubDate>Wed, 19 Mar 2008 15:38:24 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item><item><title>RE: Generate sequencial number in a BO</title><link>http://forum.strataframe.net/FindPost15037.aspx</link><description>This will work in a single user scenario, but if you have multiple users, especially if they are all adding new records, you'll get dups pretty quick.  The BO is disconnected from the db, so if another user adds a new record after the user has filled the BO, they won't know about the newly added record from the other user. There are a few of solutions for this:&lt;br&gt;
&lt;br&gt;
- If possible, just use an AutoIncrement field. The down side is that it is hard to have no holes (in some cases holes are a problem if the field is audited) and it will by a system number, not one that necessarily makes any sense in the context of the business domain.&lt;br&gt;
- Query the db for the last LineOrder number and increment it. I've used this when it is very unlikely that two people are going to be adding records at the same time (in fact, it is a bad idea in these scenarios).  Pretty much what you are doing, but if someone else adds new records while the user is in their BO, they'll see the changes.&lt;br&gt;
- Use a table to hand out the LineOrder numbers. I.e. you query this table to get the next line order number.  This is more complex because you have to deal with canceled adds, etc.&lt;br&gt;
&lt;br&gt;
The long and sort of it is to use the DB to handle this, since the disconnected BO won't know about other users changes in a timely enough fashion (usually).  I'm sure there are other ways to do this too, but thought I'd offer some ideas.</description><pubDate>Wed, 19 Mar 2008 14:24:51 GMT</pubDate><dc:creator>Greg McGuffey</dc:creator></item></channel></rss>