Group: Forum Members
Posts: 340,
Visits: 1.4K
|
I am trying to write a generic import routine that imports data into a business object and need some help on data conversion issue.
Example:
Say I have a datatable containing the data I want to import. Assume the column names in the import file match the business object's column names.
I have my customer object and want to populate it.
Dim loBO as New CustomerBO
For Each Row As DataRow In ImportFileDataTable.Rows
loBO.NewRow()
loBO.CurrentRow.Item("CompanyName") = Row.Item("CompanyName")
etc...
Next
This works fine but now I want to ensure the data from the import file converts to the appropriate type based on the business object. Example: The BO field may be integer but the data coming from the import datatable may be string... I want to convert this to the proper type.
I tried this...
Dim loType as Type
Dim loBO as New CustomerBO
For Each Row As DataRow In ImportFileDataTable.Rows
loBO.NewRow()
loType = GetType(loBO.CurrentRow.Item("CompanyName").GetType
loBO.CurrentRow.Item("CompanyName") = Ctype(Row.Item("CompanyName"),loType)
etc...
Next
Problem is 'loType' is not a valid variable for this statement... Is there anyway to dynamically set this type according to the data type on the business object without have to add a bunch of conditional statements?
Thanks,
Tim
|