Convert generic List/Enumerable to DataTable?

后端 未结 27 2600
臣服心动
臣服心动 2020-11-21 23:20

I have few methods that returns different Generic Lists.

Exists in .net any class static method or whatever to convert any list into a datatable? The only thing tha

27条回答
  •  日久生厌
    2020-11-21 23:56

     Dim counties As New List(Of County)
     Dim dtCounties As DataTable
     dtCounties = _combinedRefRepository.Get_Counties()
     If dtCounties.Rows.Count <> 0 Then
        For Each row As DataRow In dtCounties.Rows
          Dim county As New County
          county.CountyId = row.Item(0).ToString()
          county.CountyName = row.Item(1).ToString().ToUpper()
          counties.Add(county)
        Next
        dtCounties.Dispose()
     End If
    

提交回复
热议问题