Converting class object to datarow using LINQ in vb.net.

三世轮回 提交于 2019-12-24 21:29:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!