我试图区分多个列并从datatable获取数据行。但是收到错误。
Dim query As IEnumerable(Of DataRow) =
(From row As DataRow In SourceTable.AsEnumerable() _
Select row.Field(Of String)("ColumnName1"),
row.Field(Of String)("ColumnName2") ).Distinct()
以下错误:
Unable to cast object of type '<DistinctIterator>d__7a`1[System.String]'
to type 'System.Collections.Generic.IEnumerable`1[System.Data.DataRow]'.
我希望另一个数据表具有基于SourceTable中给定列的不同行。
答案 0 :(得分:4)
尝试这个然后
Dim query = From q In (From p In dt.AsEnumerable() Select New With {.col1= p("ColumnName1"), .col2 = p("ColumnName2")}) Select q.col1, q.col2 Distinct
答案 1 :(得分:0)
试试这个(我的一点猜测):
Dim query As IEnumerable(Of DataRow) =
(From row As DataRow In SourceTable.AsEnumerable().Distinct() _
Select row.Field(Of String)("ColumnName1"),
row.Field(Of String)("ColumnName2"))
答案 2 :(得分:0)
试试这个
var distinctRows = (from DataRow dRow in dTable.Rows
select new col1=dRow["dataColumn1"],col2=dRow["dataColumn2"]}).Distinct();
这是在C#中。将其转换为vb.net