StrataFrame Forum

Strong typed reference to BO field

http://forum.strataframe.net/Topic23551.aspx

By Keith Chisarik - 6/17/2009

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?
By Trent L. Taylor - 6/17/2009

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?
By Keith Chisarik - 6/17/2009

Exactly what I wanted. Lots of collections, picking the right one is the trick Smile
By Trent L. Taylor - 6/17/2009

I understand...glad to help!
By Keith Chisarik - 6/18/2009

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
By Keith Chisarik - 6/18/2009

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

By Trent L. Taylor - 6/19/2009

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.