问题
I have a list of class objects. I have a data table along with columns created. I need to insert all the data from the list into the data table. I am unable to get the LINQ right in vb.net.
I have done the same using a for each loop, but i am looking out for the LINQ code.
Sample code
Private Function ToDataTable(ByVal sampleData As List(Of ClassA))
'data table
Dim dt As New DataTable
'add columns
Dim column As DataColumn
column = New DataColumn("Name")
dt.Columns.Add(column)
column = New DataColumn("Country")
dt.Columns.Add(column)
'insert rows in data table
For Each data As ClassA In sampleData
dr = dt.NewRow()
dr(0) = data.Name
dr(1) = data.Country
dt.Rows.Add(dr)
Next
End Function
来源:https://stackoverflow.com/questions/16016465/converting-class-object-to-datarow-using-linq-in-vb-net