I have successfully used this routine to load Class Properties from a DataTable. This ONLY works if the data type in the database and the class property are both strings.
How would I tweak this so that the line below would dynamically convert the row.Value type to the correct property type of MyProp?Code:''' <summary> ''' Matches individual rows to Object Properties. ''' </summary> ''' <param name="DataTable"></param> ''' <remarks></remarks> Public Overloads Sub BindIndexDefinition(ByVal DataTable As dsQueueProperties.QueuePropertiesDataTable) Dim ThisClass As Type = Me.GetType For Each MyProp As Reflection.PropertyInfo In ThisClass.GetProperties() For Each row As dsQueueProperties.QueuePropertiesRow In DataTable.Rows If row.Name.ToLower.Equals(MyProp.Name.ToLower) Then MyProp.SetValue(Me, row.Value, Nothing) Exit For End If Next Next End Sub
Code:MyProp.SetValue(Me, row.Value, Nothing)




Reply With Quote