Saving Data and Getting First and Last Records?


Author
Message
Terry Bottorff
Terry Bottorff
Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)
Group: Forum Members
Posts: 448, Visits: 12K
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???

I know that the code may not be the best but I could not get getenumerabe to work so I was trying this way.





' Now Add the Check Numbers

If RbStockChecksBO1.MoveFirst Then

For i = 1 To RbStockChecksBO1.Count

Me.RbStockChecksBO1.checknum = nchk

nchk += 1

Me.RbStockChecksBO1.MoveNext()

Next

Me.RbStockChecksBO1.Save()

End If





What am I overlooking? TIA.

Attachments
checknums.png (102 views, 2.00 KB)
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Terry,



Here is the GetEnumerable() version, see if that work for you:



For Each record As RbStockChecksBO In Me.RbStockChecksBO1.GetEnumerable()

record.checknum = nchk

nchk += 1

Next

If Me.RbStockChecksBO1.IsDirty() Then

Me.RbStockChecksBO1.Save()

End If



Edhy Rijo

Terry Bottorff
Terry Bottorff
Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)
Group: Forum Members
Posts: 448, Visits: 12K
Edhy now I get only the first record saved with this code? See the attached figure.





For Each rec As RBStockChecksBO In Me.RbStockChecksBO1.GetEnumerable()

rec.checknum = nchk

nchk += 1

Next

If Me.RbStockChecksBO1.IsDirty() Then

Me.RbStockChecksBO1.Save()

End If





This should not be this hard? TIA.
Attachments
checknum2.png (81 views, 3.00 KB)
Terry Bottorff
Terry Bottorff
Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)
Group: Forum Members
Posts: 448, Visits: 12K
I put the messagebox in the code for my own sanity and by the attached picture you can see what I got.



For Each rec As RBStockChecksBO In Me.RbStockChecksBO1.GetEnumerable()

rec.checknum = nchk

nchk += 1

Next

If Me.RbStockChecksBO1.IsDirty() Then

Me.RbStockChecksBO1.Save()

End If





I traced the above code and it loop One (1) time thru??????? Thus saving one check number as prior post shows.??? w00t

Very bazzar.
Attachments
checknum3.png (101 views, 29.00 KB)
Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
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.



Something like this:



Dim currentFilter as string = MyBO.Filter

... do FOR..NEXT here

MyBO.Filter = currentFilter





If using BO.Sort, do the same.

Edhy Rijo

Terry Bottorff
Terry Bottorff
Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)
Group: Forum Members
Posts: 448, Visits: 12K
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.

UG.
Terry Bottorff
Terry Bottorff
Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)
Group: Forum Members
Posts: 448, Visits: 12K
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...?

Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Terry,



Sorry for delay in getting back to you!



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

Edhy Rijo

Terry Bottorff
Terry Bottorff
Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)Advanced StrataFrame User (770 reputation)
Group: Forum Members
Posts: 448, Visits: 12K
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.

I do have a question though. If you have a simple table that is say (tableA) and thus a BO with the following structure:

PK as primary key, Name, amount,

and you fill TableA with with say: me.TableABO.filldatatable("Select name, amount from TableB")

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?

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?





Edhy Rijo
E
StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)StrataFrame VIP (4.6K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Terry Bottorff (08/20/2010)
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.

I do have a question though. If you have a simple table that is say (tableA) and thus a BO with the following structure:

PK as primary key, Name, amount,

and you fill TableA with with say: me.TableABO.filldatatable("Select name, amount from TableB")

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?

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?





Hi Terry,



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.

me.TableABO.filldatatable("Select PK, name, amount from TableB")




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:



Protected Overrides Function GetCustomBindablePropertyDescriptors() As FieldPropertyDescriptor()

' Create and return a new array of FieldPropertyDescriptor objects that contains

' the ReflectionPropertyDescriptor for the Custom Fields.

Return New FieldPropertyDescriptor() _

{New ReflectionPropertyDescriptor("cfp_CustomerName", GetType(bizTransactionItems))}

End Function




BusinessFieldDisplayInEditor(), _

Description("Customer Name"), _

DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _

Public Overridable Property [cfp_CustomerName]() As String

' Check to see if datatable contains the custom field in

' case object was filled by a method that doesn't contain the field.

Get

Dim columnName As String = "cfp_CustomerName"

If Me.CurrentDataTable.Columns.Contains(columnName) Then

If Not TypeOf (Me.CurrentRow.Item(columnName)) Is DBNull Then

Return CStr(Me.CurrentRow.Item(columnName))

Else

Return String.Empty

End If

Else

Return String.Empty

End If

End Get

Set(ByVal value As String)

Dim columnName As String = "cfp_CustomerName"

If Me.CurrentDataTable.Columns.Contains(columnName) Then

Me.CurrentRow.Item(columnName) = value

End If

End Set

End Property





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 BigGrin



P.S.

Copy and paste the code in VS so it will make more sense. Hehe


Edhy Rijo

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