Foxtable(狐表)用户栏目专家坐堂 → 在表有很多字段,要删除 学号 和 试卷号 相同的数据列,怎么写代码?


  共有2653人关注过本帖树形打印复制链接

主题:在表有很多字段,要删除 学号 和 试卷号 相同的数据列,怎么写代码?

帅哥哟,离线,有人找我吗?
大红袍
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:贵宾 帖子:39310 积分:196782 威望:0 精华:1 注册:2015/4/25 9:23:00
  发帖心情 Post By:2015/6/15 16:10:00 [显示全部帖子]

参考代码

 

Dim str As String = "第一列,第二列"
Dim idx As String = ""
Dim ary() As String = str.Split(",")
Dim pdr As DataRow = Nothing
Dim count As Integer = 0
For Each dr As DataRow In DataTables("表A").Select("第一列 is not null", str)
    Dim flag As Boolean = False
    For Each a As String In ary
        If pdr IsNot Nothing AndAlso dr(a) <> pdr(a) Then
            flag = True
        End If
    Next
    If flag = False Then
        count += 1
    Else
        'If count = 1 Then
            idx &= pdr("_Identify") & ","
        'End If
        count = 1
    End If
    pdr = dr
Next

For Each a As String In ary
    If pdr IsNot Nothing AndAlso Tables("表A").Rows(Tables("表A").Rows.count-2)(a) <> pdr(a) Then
        idx &= pdr("_Identify") & ","
    End If
Next

DataTables("表A").DeleteFor("_Identify not in (" & idx.trim(",") & ")")


 回到顶部