以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 如何修正代码实现 多行数据指定字段值相同的行保留一行 不相同的行保留 最后当前表中数据指定条件下的数据没有重复行 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=173261) |
-- 作者:cnsjroom -- 发布时间:2021/11/21 23:57:00 -- 如何修正代码实现 多行数据指定字段值相同的行保留一行 不相同的行保留 最后当前表中数据指定条件下的数据没有重复行 如何修正代码实现 多行数据指定字段值相同的行保留一行 不相同的行保留 最后当前表中数据指定条件下的数据没有重复行 谢谢! 当前代码运行之后,出现如图问题【当有2个重复数据行时,能够正确显示一行,当有三个重复数据时,显示两条数据行,当只有一行数据时,筛选的结果直接没有了,麻烦老师们帮忙修正一下,只要是重复的数据不管是多少行都只保留一行,不重复的数据,保留,最终实现表中数据在选择比对的字段条件下无重复数据行】 当前代码如下:Dim s As String Dim l As WinForm.CheckedListBox = e.Form.Controls("CheckedListBox1") For Each Index As Integer In l.CheckedIndices s = s & "," & l.Items(Index) Next s = s.trim(",") Dim cs As String = s Dim idx As String = "" Dim lst As new List(of String) Dim flag As Boolean Dim s1 As String = vars("不为空字段") & " is not null" Dim drs As List(Of DataRow) = DataTables(Vars("btname")).Select(s1, cs) Dim pdr As DataRow = drs(0) Dim dr As DataRow For i As Integer = 1 To drs.count -1 dr = drs(i) flag = False For Each c As String In cs.split(",") If pdr(c) = dr(c) Then flag = True Exit For End If Next If flag = False Then If lst.Contains(pdr("_Identify")) = False lst.add( pdr("_Identify") ) End If lst.add( dr("_Identify") ) End If pdr = dr Next If lst.count > 0 Then idx = String.Join(",",lst.ToArray) Dim s2 As String = s1 & " And _Identify not In (" & idx.trim(",") & ")" Tables(Vars("btname")).filter = s2 Dim dtb As New DataTableBuilder("比对表") Dim cnt As Integer = DataTables(Vars("btname")).DataCols.Count Dim nms(cnt-1) As String For i As Integer = 0 To cnt-1 nms(i) = DataTables(Vars("btname")).DataCols(i).name dtb.AddDef(nms(i), Gettype(String), 255) Next dtb.Build() Dim tb3 As WinForm.Table = e.Form.Controls("Table3") tb3.Table.DataSource = DataTables("比对表") tb3.Table.AutoSizeCols() \'自适应列宽 For Each a1 As Row In Tables(Vars("btname")).rows If a1 IsNot Nothing Then Dim r As Row = Tables("比对表").addnew For Each dc As Col In Tables(Vars("btname")).Cols r(dc.name) = a1(dc.name) Next End If Next Else MessageBox.Show("没有重复数据!") End If |
-- 作者:cnsjroom -- 发布时间:2021/11/22 12:10:00 -- RepeatFilter 此方法用于重复值筛选,关于重复值筛选,参考:重复值筛选 语法 RepeatFilter(ColName, Mode) ColName: 用于筛选的列 示例 在表A进行筛选,显示第一列有重复值的行: Tables("表A").RepeatFilter("第一列", 0) 当前帮助有如上说明文档 除了这个方法之外 是否可以在一楼的代码中补正显示呢? |
-- 作者:有点蓝 -- 发布时间:2021/11/22 13:46:00 -- Dim s As String dim filter as string Dim l As WinForm.CheckedListBox = e.Form.Controls("CheckedListBox1") dim idx as integer = 0 For Each Index As Integer In l.CheckedIndices dim c as string = l.Items(Index) s = s & "|" & c if filter > "" then filter = filter & " and " if dataTables(Vars("btname")).datacols(c).IsNumeric filter = filter & c & "={" & idx & "}" elseif dataTables(Vars("btname")).datacols(c).IsDate filter = filter & c & "=#{" & idx & "}#" else filter = filter & c & "=\'{" & idx & "}\'" end if idx += 1 Next s = s.trim("|") dim dr as datarow 生成"比对表"的代码 for each sr() as string in dataTables(Vars("btname")).GetValues(s) dr = dataTables(Vars("btname")).find(CExp(filter,sr)) if dr isnot nothing then Dim r As Row = Tables("比对表").addnew For Each dc As Col In Tables(Vars("btname")).Cols r(dc.name) = dr(dc.name) Next end if next
|