以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  在表有很多字段,要删除 学号 和 试卷号 相同的数据列,怎么写代码?  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=70077)

--  作者:zgjmost
--  发布时间:2015/6/15 15:56:00
--  在表有很多字段,要删除 学号 和 试卷号 相同的数据列,怎么写代码?
在表有很多字段,要删除 学号 和 试卷号 相同的数据列,怎么写代码?
--  作者:Bin
--  发布时间:2015/6/15 16:08:00
--  
什么意思, 删除相同的行 还是列?   举个例子看看
--  作者:大红袍
--  发布时间: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(",") & ")")