Strong typed reference to BO field


Author
Message
Keith Chisarik
Keith Chisarik
StrataFrame VIP (1.6K reputation)StrataFrame VIP (1.6K reputation)StrataFrame VIP (1.6K reputation)StrataFrame VIP (1.6K reputation)StrataFrame VIP (1.6K reputation)StrataFrame VIP (1.6K reputation)StrataFrame VIP (1.6K reputation)StrataFrame VIP (1.6K reputation)StrataFrame VIP (1.6K reputation)
Group: StrataFrame Users
Posts: 939, Visits: 40K
I have a list of field names in a database. I want to get a programatic reference to the corresponding field property on the BO so I can set its value. How?

Keith Chisarik
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
So you have a string with a field name in it, correct? And you want to retrieve the data from that field on the BO? For example:



Dim myField As String = "cust_FirstName"

Dim r As Object



r = MyBO.Items(myField)




Or are you wanting to use reflection and actually get to the FieldPropertyDescriptor?
Keith Chisarik
Keith Chisarik
StrataFrame VIP (1.6K reputation)StrataFrame VIP (1.6K reputation)StrataFrame VIP (1.6K reputation)StrataFrame VIP (1.6K reputation)StrataFrame VIP (1.6K reputation)StrataFrame VIP (1.6K reputation)StrataFrame VIP (1.6K reputation)StrataFrame VIP (1.6K reputation)StrataFrame VIP (1.6K reputation)
Group: StrataFrame Users
Posts: 939, Visits: 40K
Exactly what I wanted. Lots of collections, picking the right one is the trick Smile

Keith Chisarik
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
I understand...glad to help!
Keith Chisarik
Keith Chisarik
StrataFrame VIP (1.6K reputation)StrataFrame VIP (1.6K reputation)StrataFrame VIP (1.6K reputation)StrataFrame VIP (1.6K reputation)StrataFrame VIP (1.6K reputation)StrataFrame VIP (1.6K reputation)StrataFrame VIP (1.6K reputation)StrataFrame VIP (1.6K reputation)StrataFrame VIP (1.6K reputation)
Group: StrataFrame Users
Posts: 939, Visits: 40K
almost... In your example above I want to use r to set the value of the bo.field to something, not just read the data value

Keith Chisarik
Keith Chisarik
Keith Chisarik
StrataFrame VIP (1.6K reputation)StrataFrame VIP (1.6K reputation)StrataFrame VIP (1.6K reputation)StrataFrame VIP (1.6K reputation)StrataFrame VIP (1.6K reputation)StrataFrame VIP (1.6K reputation)StrataFrame VIP (1.6K reputation)StrataFrame VIP (1.6K reputation)StrataFrame VIP (1.6K reputation)
Group: StrataFrame Users
Posts: 939, Visits: 40K
I got this to work by modifying the underlying datatable, I would rather use the BO field properties.

Background on the why: I have a need to convert VFP tables to SQL, the target structures will be a moving target so I came up with a system that allows you to map VFP fields to SQL fields, and apply any conversion rules that need to be applied. These mapping rules are stored in a table so they can be modified and re-run as many times as needed as the process evolves and the target tables structures change.

For Each row_conversionrule As BUSINESS.bo_mapfields In Me.Bo_mapfields.GetEnumerable()

Dim sqlField As String = row_conversionrule.mapf_sqlfield

Dim s As Object

Dim vfpField As String = row_conversionrule.mapf_vfpfield

Dim v As Object

s = Me.Bo_consignee1.Item(sqlField)

v = Me.Vfpbo_consig1.Item(vfpField)

s = v ' only changes the string object values, not the BO field value

'workaround below

Dim x As DataTable = Me.Bo_consignee1.CurrentDataTable

Dim y As DataRow = x.Rows.Item(bo.CurrentRowIndex)

y.Item(sqlField) = v

Next



Keith Chisarik
Trent Taylor
Trent Taylor
StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)StrataFrame Developer (10K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 6.9K
Looking at your code, why can't you just use the CurrentRow property.



Instead of:



Dim x As DataTable = Me.Bo_consignee1.CurrentDataTable

Dim y As DataRow = x.Rows.Item(bo.CurrentRowIndex)

y.Item(sqlField) = v




Use:



Bo_consignee1.Item(sqlField) = v




There is nothing wrong with this approach. I will do this a fair amount myself at times.
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