var value=(from v in datatable select v.A).Distinct().ToList();
#6
您在生成datatable之前不是要查询吗?把查询的SQL语句改为select distinct A from。。。不就行了?
#7
Private Function GetListOne(ByVal dt As DataTable, ByVal strItem As String) As DataTable
Dim dCount As Long = dt.Rows.Count
Dim r As Long
Dim dCol As New DataColumn
'添加一列,用来记录有没有 相同记录
With dCol
.ColumnName = "nums"
.DefaultValue = 0
End With
dt.Columns.Add(dCol)
Dim sValue As String
Dim p As Long
For r = 0 To dCount - 2
sValue = dt.Rows(r).Item(strItem).ToString
For p = r + 1 To dCount - 1
If dt.Rows(p).Item("nums") = 0 Then
If dt.Rows(p).Item(strItem).ToString = sValue Then
'如果有相同,就用1表示
dt.Rows(p).Item("nums") = 1
End If
End If
Next
Next
Dim dv As DataView = dt.DefaultView
dv.RowFilter = "nums=0"
dt = dv.ToTable
dt.Columns.Remove("nums")
Return dt
End Function
#1
sql里面 group by a
#2
distinct A
#3
sql里面 group by a
都说了在datatable中,如果是sql server就不用这么麻烦了。
#4
sql里面 group by a
都说了在datatable中,如果是sql server就不用这么麻烦了。
用linq
#5
var value=(from v in datatable select v.A).Distinct().ToList();
#6
您在生成datatable之前不是要查询吗?把查询的SQL语句改为select distinct A from。。。不就行了?
#7
Private Function GetListOne(ByVal dt As DataTable, ByVal strItem As String) As DataTable
Dim dCount As Long = dt.Rows.Count
Dim r As Long
Dim dCol As New DataColumn
'添加一列,用来记录有没有 相同记录
With dCol
.ColumnName = "nums"
.DefaultValue = 0
End With
dt.Columns.Add(dCol)
Dim sValue As String
Dim p As Long
For r = 0 To dCount - 2
sValue = dt.Rows(r).Item(strItem).ToString
For p = r + 1 To dCount - 1
If dt.Rows(p).Item("nums") = 0 Then
If dt.Rows(p).Item(strItem).ToString = sValue Then
'如果有相同,就用1表示
dt.Rows(p).Item("nums") = 1
End If
End If
Next
Next
Dim dv As DataView = dt.DefaultView
dv.RowFilter = "nums=0"
dt = dv.ToTable
dt.Columns.Remove("nums")
Return dt