3
我想從一個動態LINQ查詢到一個DataTable的結果。試圖直接將查詢到的DataTable給了我這個錯誤:Casting從System.Linq.EnumerableQuery到System.Data.Datatable(使用動態LINQ)
Unable to cast object of type 'System.Linq.EnumerableQuery`1[DynamicClass1]' to type 'System.Data.DataTable'.
我的代碼是:
Dim query = tbl.AsEnumerable.AsQueryable.Select("new(it[""curr""] as Curry)")
Dim tbl As DataTable = query
我用盡:
Dim query As IEnumerable(Of DataRow) = tbl.AsEnumerable.AsQueryable.Select("new(it[""curr""] as Curry)").Cast(Of DataRow)()
Dim tbl1 As DataTable = query.CopyToDataTable
但是這給了我:
Unable to cast object of type 'DynamicClass1' to type 'System.Data.DataRow'.