以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  请教:多字段组合后的唯一性约束检查  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=94548)

--  作者:dogman
--  发布时间:2016/12/26 16:07:00
--  请教:多字段组合后的唯一性约束检查
如有以下客户收款表:

图片点击可在新窗口打开查看此主题相关图片如下:qq截图20161226154945.png
图片点击可在新窗口打开查看
我要确保其中6个字段:帐期、姓名、证件号码、帐款性质、缴费年月、社保险种
在整个表中组合后的唯一性。

在表属性的DataColChanged事件中代码如下:
Select Case e.DataCol.Name
    Case "帐期","姓名","证件号码","帐款性质","缴费年月","社保险种"
            Dim cnt As Integer = e.DataTable.SQLCompute( "Count([_Identify])", _
            "帐期 = \'" & e.DataRow("帐期") & "\' And " & _
            "姓名 = \'" & e.DataRow("姓名") & "\' And " & _
            "证件号码 = \'" & e.DataRow("证件号码") & "\' And " & _
            "帐款性质 = \'" & e.DataRow("帐款性质") & "\' And " & _
            "缴费年月 = \'" & e.DataRow("缴费年月") & "\' And " & _
            "社保险种 = \'" & e.DataRow("社保险种") & "\'" )

            e.DataRow("UNIQUE检查") = cnt
        End If
        
End Select

但是整表运行 重置列 要将近2分钟!之后才会在"UNIQUE检查"列显示结果。
是不是这样检查太菜鸟了?


--  作者:有点色
--  发布时间:2016/12/26 16:17:00
--  

 不要重置列,单独做一个按钮,执行全表的操作。

 

Dim dt As DataTable = DataTables("表A")
Dim cmd As new SQLCommand
cmd.CommandText = "select * from {" & dt.name & "}"
Dim dt_temp As DataTable = cmd.ExecuteReader
For Each dr As DataRow In dt.datarows
    Dim cnt As Integer = dt_temp.Compute( "Count([_Identify])", _
    "帐期 = \'" & dr("帐期") & "\' And " & _
    "姓名 = \'" & dr("姓名") & "\' And " & _
    "证件号码 = \'" & dr("证件号码") & "\' And " & _
    "帐款性质 = \'" & dr("帐款性质") & "\' And " & _
    "缴费年月 = \'" & dr("缴费年月") & "\' And " & _
    "社保险种 = \'" & dr("社保险种") & "\'" )
  
    dr("UNIQUE检查") = cnt
Next


--  作者:有点色
--  发布时间:2016/12/26 16:19:00
--  

 筛选重复,还可以这样做

 

http://www.foxtable.com/bbs/dispbbs.asp?BoardID=2&ID=76545&replyID=529794&skin=1

 

 

 


--  作者:dogman
--  发布时间:2016/12/26 16:57:00
--  
thanks!