I have read many posts on this topic; among them and most recently .NET - Convert Generic Collection to Data Table. Unfortunately, all to no avail.
I have a generic coll
Following @Hans Passant function if anyone is dealing with nullable types:
For Each field As FieldInfo In fields
' Extra check for nullable
If field.FieldType.AssemblyQualifiedName.Contains("System.Nullable") Then
' Insert proper type
If field.FieldType.AssemblyQualifiedName.Contains("System.DateTime") Then
table.Columns.Add(field.Name, Type.GetType("System.DateTime"))
End If
Else
table.Columns.Add(field.Name, field.FieldType)
End If
Next
Values:
For Each item As T In list
Dim row As DataRow = table.NewRow()
For Each field As FieldInfo In fields
' Check if value is null
If field.GetValue(item) is nothing Then
Continue For
End If
row(field.Name) = field.GetValue(item)
Next
table.Rows.Add(row)
Next