去掉重复项,怎么做。

ruhong1 2017-08-27 10:48:25
现在有一个datatable

A S E
张三 9:00 10:00
李四 10:00 11:00
张三 11:00 12:00


我想得到
张三
李四

有没有简单的方式?
...全文
465 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
xyxcc177109 2017-09-24
  • 打赏
  • 举报
回复
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
king-520 2017-09-17
  • 打赏
  • 举报
回复
您在生成datatable之前不是要查询吗?把查询的SQL语句改为select distinct A from。。。不就行了?
snlixing 2017-08-30
  • 打赏
  • 举报
回复
var value=(from v in datatable select v.A).Distinct().ToList();
snlixing 2017-08-28
  • 打赏
  • 举报
回复
distinct A
threenewbee 2017-08-28
  • 打赏
  • 举报
回复
引用 3 楼 ruhong1 的回复:
[quote=引用 1 楼 caozhy 的回复:] sql里面 group by a
都说了在datatable中,如果是sql server就不用这么麻烦了。[/quote] 用linq
ruhong1 2017-08-28
  • 打赏
  • 举报
回复
引用 1 楼 caozhy 的回复:
sql里面 group by a
都说了在datatable中,如果是sql server就不用这么麻烦了。
threenewbee 2017-08-27
  • 打赏
  • 举报
回复
sql里面 group by a

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧