﻿<?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?)  » Saving Data and Getting First and Last Records?</title><generator>InstantForum 2017-1 Final</generator><description>StrataFrame Forum</description><link>http://forum.strataframe.net/</link><webMaster>StrataFrame Forum</webMaster><lastBuildDate>Tue, 09 Jun 2026 05:47:50 GMT</lastBuildDate><ttl>20</ttl><item><title>Saving Data and Getting First and Last Records?</title><link>http://forum.strataframe.net/FindPost27992.aspx</link><description>I was just trying this simple code and notice in attachment that the only check numbers that got saved are the first and last ones???&lt;br&gt;
I know that the code may not be the best but I could not get getenumerabe to work so I was trying this way.&lt;br&gt;
&lt;br&gt;
[codesnippet]       &lt;br&gt;
 ' Now Add the Check Numbers&lt;br&gt;
        If RbStockChecksBO1.MoveFirst Then&lt;br&gt;
            For i = 1 To RbStockChecksBO1.Count&lt;br&gt;
                Me.RbStockChecksBO1.checknum = nchk&lt;br&gt;
                nchk += 1&lt;br&gt;
                Me.RbStockChecksBO1.MoveNext()&lt;br&gt;
            Next&lt;br&gt;
            Me.RbStockChecksBO1.Save()&lt;br&gt;
        End If&lt;br&gt;
[/codesnippet]&lt;br&gt;
&lt;br&gt;
What am I overlooking?  TIA.&lt;br&gt;</description><pubDate>Fri, 20 Aug 2010 11:02:48 GMT</pubDate><dc:creator>Terry Bottorff</dc:creator></item><item><title>RE: Saving Data and Getting First and Last Records?</title><link>http://forum.strataframe.net/FindPost28027.aspx</link><description>OK, Thanks I will put some time on this.</description><pubDate>Fri, 20 Aug 2010 11:02:48 GMT</pubDate><dc:creator>Terry Bottorff</dc:creator></item><item><title>RE: Saving Data and Getting First and Last Records?</title><link>http://forum.strataframe.net/FindPost28025.aspx</link><description>[quote][b]Terry Bottorff (08/20/2010)[/b][hr]Thank you for the extreme amount of help you have given me. I will try and get back to this later and see what is happening. &lt;br&gt;
I do have a question though. If you have a simple table that is say (tableA) and thus a BO with the following structure:&lt;br&gt;
PK as primary key, Name, amount,&lt;br&gt;
and you fill TableA with with say: me.TableABO.filldatatable("Select name, amount from TableB")&lt;br&gt;
Can you put something in the Select so that the PK column will exist and not cause problems when you try and save tableA's BO?&lt;br&gt;
If you don't have something there it won't let you save because the BO does not have a Primary Key and if I put save 1 in for all the records and the PK is autoincrementing I get an error?&lt;br&gt;
[/quote]&lt;br&gt;
&lt;br&gt;
Hi Terry,&lt;br&gt;
&lt;br&gt;
If you plan to update the table via the BO you MUST have the PK column as part of your select statement so it will know which record to update.&lt;br&gt;
[quote]me.TableABO.filldatatable("Select PK, name, amount from TableB")[/quote]&lt;br&gt;
&lt;br&gt;
StrataFrame Business Objects are very, very, very flexible and that make them powerful. One sample I used a lot is having a JOIN statement to select a field description, then in the BO I have a Custom Field Property that will return the column name for the description field, of course your SQL statement should have that column as part of it.  Here is a sample of one of my Custom Field Properties:&lt;br&gt;
[codesnippet]&lt;br&gt;
  Protected Overrides Function GetCustomBindablePropertyDescriptors() As FieldPropertyDescriptor()&lt;br&gt;
        ' Create and return a new array of FieldPropertyDescriptor objects that contains &lt;br&gt;
        ' the ReflectionPropertyDescriptor for the Custom Fields.&lt;br&gt;
        Return New FieldPropertyDescriptor() _&lt;br&gt;
       {New ReflectionPropertyDescriptor("cfp_CustomerName", GetType(bizTransactionItems))}&lt;br&gt;
    End Function&lt;br&gt;
&lt;br&gt;
  &lt;Browsable(False), _&lt;br&gt;
    BusinessFieldDisplayInEditor(), _&lt;br&gt;
    Description("Customer Name"), _&lt;br&gt;
    DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)&gt; _&lt;br&gt;
    Public Overridable Property [cfp_CustomerName]() As String&lt;br&gt;
        ' Check to see if datatable contains the custom field in&lt;br&gt;
        ' case object was filled by a method that doesn't contain the field.&lt;br&gt;
        Get&lt;br&gt;
            Dim columnName As String = "cfp_CustomerName"&lt;br&gt;
            If Me.CurrentDataTable.Columns.Contains(columnName) Then&lt;br&gt;
                If Not TypeOf (Me.CurrentRow.Item(columnName)) Is DBNull Then&lt;br&gt;
                    Return CStr(Me.CurrentRow.Item(columnName))&lt;br&gt;
                Else&lt;br&gt;
                    Return String.Empty&lt;br&gt;
                End If&lt;br&gt;
            Else&lt;br&gt;
                Return String.Empty&lt;br&gt;
            End If&lt;br&gt;
        End Get&lt;br&gt;
        Set(ByVal value As String)&lt;br&gt;
            Dim columnName As String = "cfp_CustomerName"&lt;br&gt;
            If Me.CurrentDataTable.Columns.Contains(columnName) Then&lt;br&gt;
                Me.CurrentRow.Item(columnName) = value&lt;br&gt;
            End If&lt;br&gt;
        End Set&lt;br&gt;
    End Property&lt;br&gt;
[/codesnippet]&lt;br&gt;
&lt;br&gt;
Like I said, the field column "cfp_CustomerName" should exist in the SQL statement used to fill the BO, if not, the used of the Custom Field Property BO.cfp_CustomerName will just return a blank space.  There are a lot of samples in the forums on how to use the Custom Field Properties as well as in the SF help file.  I must admit that the above code is a combination of multiple SF developers suggestion in the forums, so it is not my idea :D&lt;br&gt;
&lt;br&gt;
P.S.&lt;br&gt;
Copy and paste the code in VS so it will make more sense. :hehe:&lt;br&gt;</description><pubDate>Fri, 20 Aug 2010 10:45:42 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item><item><title>RE: Saving Data and Getting First and Last Records?</title><link>http://forum.strataframe.net/FindPost28021.aspx</link><description>Thank you for the extreme amount of help you have given me. I will try and get back to this later and see what is happening. &lt;br&gt;
I do have a question though. If you have a simple table that is say (tableA) and thus a BO with the following structure:&lt;br&gt;
PK as primary key, Name, amount,&lt;br&gt;
and you fill TableA with with say: me.TableABO.filldatatable("Select name, amount from TableB")&lt;br&gt;
Can you put something in the Select so that the PK column will exist and not cause problems when you try and save tableA's BO?&lt;br&gt;
If you don't have something there it won't let you save because the BO does not have a Primary Key and if I put save 1 in for all the records and the PK is autoincrementing I get an error?&lt;br&gt;
&lt;br&gt;
&lt;br&gt;</description><pubDate>Fri, 20 Aug 2010 09:42:52 GMT</pubDate><dc:creator>Terry Bottorff</dc:creator></item><item><title>RE: Saving Data and Getting First and Last Records?</title><link>http://forum.strataframe.net/FindPost28015.aspx</link><description>Hi Terry,&lt;br&gt;
&lt;br&gt;
Sorry for delay in getting back to you!  &lt;br&gt;
&lt;br&gt;
That is very weird, something else may be happening with your whole code, I used BO.GetEnumerable() all over since Trent introduced it to us.  If you still want to give this another try, please post the whole method code or email it to me so I can take a wider look.:cool:</description><pubDate>Thu, 19 Aug 2010 21:52:39 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item><item><title>RE: Saving Data and Getting First and Last Records?</title><link>http://forum.strataframe.net/FindPost28014.aspx</link><description>I found a way around it by executing an ExecuteScalar and all seems to be good. I still don't have a clue as to why it worked the way it was. Oh well maybe a Window's Thing, or a SQL Thing or .... Thing...?&lt;br&gt;</description><pubDate>Thu, 19 Aug 2010 16:59:37 GMT</pubDate><dc:creator>Terry Bottorff</dc:creator></item><item><title>RE: Saving Data and Getting First and Last Records?</title><link>http://forum.strataframe.net/FindPost28005.aspx</link><description>None that I put on. I did fill the BO with an 'order by' in the stored procedure that I used to fill the BO. I know that should not count. &lt;br&gt;
UG.</description><pubDate>Wed, 18 Aug 2010 15:13:16 GMT</pubDate><dc:creator>Terry Bottorff</dc:creator></item><item><title>RE: Saving Data and Getting First and Last Records?</title><link>http://forum.strataframe.net/FindPost27998.aspx</link><description>Are you using some filter or sort in the BO? if so, then reset those before the loop and put them back after the loop.&lt;br&gt;
&lt;br&gt;
Something like this:&lt;br&gt;
[codesnippet]&lt;br&gt;
Dim currentFilter as string =  MyBO.Filter&lt;br&gt;
... do FOR..NEXT here&lt;br&gt;
MyBO.Filter = currentFilter&lt;br&gt;
[/codesnippet]&lt;br&gt;
&lt;br&gt;
If using BO.Sort, do the same.</description><pubDate>Wed, 18 Aug 2010 10:34:15 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item><item><title>RE: Saving Data and Getting First and Last Records?</title><link>http://forum.strataframe.net/FindPost27997.aspx</link><description>I put the messagebox in the code for my own sanity and by the attached picture you can see what I got.&lt;br&gt;
[codesnippet] &lt;br&gt;
For Each rec As RBStockChecksBO In Me.RbStockChecksBO1.GetEnumerable()&lt;br&gt;
                rec.checknum = nchk&lt;br&gt;
                nchk += 1&lt;br&gt;
            Next&lt;br&gt;
            If Me.RbStockChecksBO1.IsDirty() Then&lt;br&gt;
                Me.RbStockChecksBO1.Save()&lt;br&gt;
            End If&lt;br&gt;
[/codesnippet]&lt;br&gt;
&lt;br&gt;
I traced the above code and it loop One (1) time thru??????? Thus saving one check number as prior post shows.??? :w00t:&lt;br&gt;
Very bazzar.</description><pubDate>Wed, 18 Aug 2010 10:24:37 GMT</pubDate><dc:creator>Terry Bottorff</dc:creator></item><item><title>RE: Saving Data and Getting First and Last Records?</title><link>http://forum.strataframe.net/FindPost27996.aspx</link><description>Edhy now I get only the first record saved with this code? See the attached figure. &lt;br&gt;
&lt;br&gt;
[codesnippet]&lt;br&gt;
For Each rec As RBStockChecksBO In Me.RbStockChecksBO1.GetEnumerable()&lt;br&gt;
                rec.checknum = nchk&lt;br&gt;
                nchk += 1&lt;br&gt;
            Next&lt;br&gt;
            If Me.RbStockChecksBO1.IsDirty() Then&lt;br&gt;
                Me.RbStockChecksBO1.Save()&lt;br&gt;
            End If&lt;br&gt;
[/codesnippet]&lt;br&gt;
&lt;br&gt;
This should not be this hard? TIA.</description><pubDate>Wed, 18 Aug 2010 10:07:36 GMT</pubDate><dc:creator>Terry Bottorff</dc:creator></item><item><title>RE: Saving Data and Getting First and Last Records?</title><link>http://forum.strataframe.net/FindPost27994.aspx</link><description>Hi Terry,&lt;br&gt;
&lt;br&gt;
Here is the GetEnumerable() version, see if that work for you:&lt;br&gt;
[codesnippet]&lt;br&gt;
 For Each record As RbStockChecksBO In Me.RbStockChecksBO1.GetEnumerable()&lt;br&gt;
            record.checknum = nchk&lt;br&gt;
            nchk += 1&lt;br&gt;
        Next&lt;br&gt;
        If Me.RbStockChecksBO1.IsDirty() Then&lt;br&gt;
            Me.RbStockChecksBO1.Save()&lt;br&gt;
        End If&lt;br&gt;
[/codesnippet]</description><pubDate>Tue, 17 Aug 2010 15:44:50 GMT</pubDate><dc:creator>Edhy Rijo</dc:creator></item></channel></rss>